move formatting from JS to PHP
[mdref/mdref] / mdref / Generator / Prop.php
1 <?php
2
3 namespace mdref\Generator;
4
5 use mdref\Generator;
6 use phpDocumentor\Reflection\{DocBlock, DocBlock\Tags};
7
8 class Prop extends Scrap {
9 public function __toString() : string {
10 return parent::toString(__FILE__, __COMPILER_HALT_OFFSET__, [
11 "tag" => $this->getVarTag($this->ref->getName())
12 ]);
13 }
14
15 }
16
17 /** @var $gen Generator */
18 /** @var $ref \ReflectionProperty */
19 /** @var $doc ?DocBlock */
20 /** @var $tag ?Tags\Param */
21
22 __HALT_COMPILER();
23 <?= implode(" ", \Reflection::getModifierNames($ref->getModifiers()))
24 ?> <?= $ref->hasType() ? $ref->getType() : ($tag?->getType() ?? "mixed")
25 ?> $<?=$ref->getName() ?><?php
26 if ($ref->hasDefaultValue()) :
27 ?> = <?php var_export($ref->getDefaultValue()) ?><?php
28 elseif (($params = $ref->getDeclaringClass()->getConstructor()?->getParameters())) :
29 foreach ($params as $param) :
30 if ($param->getName() === $ref->name) :
31 if ($param->isDefaultValueAvailable()) :
32 ?> = <?php var_export($param->getDefaultValue()) ?><?php
33 endif;
34 break;
35 endif;
36 endforeach;
37 endif;
38
39 if (($desc = $doc?->getSummary())) :
40 ?><?= " \n $desc"
41 ?><?php
42 endif;
43
44 ?><?= "\n"
45 ?><?php
46