move formatting from JS to PHP
[mdref/mdref] / mdref / Generator / Param.php
1 <?php
2
3 namespace mdref\Generator;
4
5 use mdref\Generator;
6 use phpDocumentor\Reflection\{DocBlock, DocBlock\Tags};
7
8
9 class Param extends Scrap {
10 public function __toString() : string {
11 return parent::toString(__FILE__, __COMPILER_HALT_OFFSET__, [
12 "tag" => $this->getParamTag($this->ref->getName())
13 ]);
14 }
15 }
16
17 /** @var $gen Generator */
18 /** @var $ref \ReflectionParameter */
19 /** @var $doc ?DocBlock */
20 /** @var $tag ?Tags\Param */
21
22 __HALT_COMPILER();
23 * <?php
24 if ($ref->isOptional()) :
25 ?>Optional <?php
26 endif;
27 ?><?= $ref->hasType() ? $ref->getType() : str_replace("\\ref", "Reference",$tag?->getType() ?? "mixed")
28 ?> <?php
29 if ($ref->isVariadic()) : ?>
30 ?>...<?php
31 endif;
32 if ($ref->isPassedByReference()) :
33 ?>&<?php
34 endif;
35 ?>$<?= $ref->getName()
36 ?><?php
37 if ($ref->isDefaultValueAvailable()) :
38 ?> = <?php var_export($ref->getDefaultValue()) ?><?php
39 endif;
40
41 if (($desc = $tag?->getDescription() ?? $doc?->getSummary())) :
42 ?><?= " \n "
43 ?><?= $desc
44 ?><?php
45 endif;
46 ?>
47
48 <?php