|
18 | 18 | use phpDocumentor\Reflection\Php\ProjectFactoryStrategy;
|
19 | 19 | use phpDocumentor\Reflection\Php\StrategyContainer;
|
20 | 20 | use phpDocumentor\Reflection\PrettyPrinter;
|
| 21 | +use phpDocumentor\Reflection\Type; |
| 22 | +use phpDocumentor\Reflection\TypeResolver; |
21 | 23 | use phpDocumentor\Reflection\Types\Context;
|
22 | 24 | use PhpParser\Node\Expr\Variable;
|
| 25 | +use PhpParser\Node\NullableType; |
23 | 26 | use PhpParser\Node\Param;
|
24 | 27 | use Webmozart\Assert\Assert;
|
25 | 28 |
|
@@ -68,6 +71,24 @@ protected function doCreate($object, StrategyContainer $strategies, ?Context $co
|
68 | 71 | $default = $this->valueConverter->prettyPrintExpr($object->default);
|
69 | 72 | }
|
70 | 73 |
|
71 |
| - return new ArgumentDescriptor((string) $object->var->name, $default, $object->byRef, $object->variadic); |
| 74 | + $argumentDescriptor = new ArgumentDescriptor((string) $object->var->name, $default, $object->byRef, $object->variadic); |
| 75 | + |
| 76 | + if (!empty($object->type)) { |
| 77 | + $argumentDescriptor->addType($this->createType($object)); |
| 78 | + } |
| 79 | + |
| 80 | + return $argumentDescriptor; |
| 81 | + } |
| 82 | + |
| 83 | + private function createType(Param $arg, ?Context $context = null): Type |
| 84 | + { |
| 85 | + $typeResolver = new TypeResolver(); |
| 86 | + if ($arg->type instanceof NullableType) { |
| 87 | + $typeString = '?' . $arg->type->type; |
| 88 | + } else { |
| 89 | + $typeString = (string) $arg->type; |
| 90 | + } |
| 91 | + |
| 92 | + return $typeResolver->resolve($typeString, $context); |
72 | 93 | }
|
73 | 94 | }
|
0 commit comments