Skip to content

Commit 79df6d4

Browse files
committed
use prettyprinter to extract default value of arguments
1 parent 851cbee commit 79df6d4

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/phpDocumentor/Reflection/Php/Factory/Argument.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use phpDocumentor\Reflection\Php\Factory;
1818
use phpDocumentor\Reflection\Php\ProjectFactoryStrategy;
1919
use phpDocumentor\Reflection\Php\StrategyContainer;
20+
use phpDocumentor\Reflection\PrettyPrinter;
2021
use phpDocumentor\Reflection\Types\Context;
2122
use PhpParser\Node\Param;
2223

@@ -28,6 +29,20 @@
2829
*/
2930
final class Argument implements ProjectFactoryStrategy
3031
{
32+
/**
33+
* @var PrettyPrinter
34+
*/
35+
private $valueConverter;
36+
37+
/**
38+
* Initializes the object.
39+
*
40+
* @param PrettyPrinter $prettyPrinter
41+
*/
42+
public function __construct(PrettyPrinter $prettyPrinter)
43+
{
44+
$this->valueConverter = $prettyPrinter;
45+
}
3146

3247
/**
3348
* Returns true when the strategy is able to handle the object.
@@ -61,6 +76,11 @@ public function create($object, StrategyContainer $strategies, Context $context
6176
);
6277
}
6378

64-
return new ArgumentDescriptor($object->name, $object->default, $object->byRef, $object->variadic);
79+
$default = null;
80+
if ($object->default !== null) {
81+
$default = $this->valueConverter->prettyPrintExpr($object->getValue());
82+
}
83+
84+
return new ArgumentDescriptor($object->name, $default, $object->byRef, $object->variadic);
6585
}
6686
}

0 commit comments

Comments
 (0)