diff --git a/src/phpDocumentor/Reflection/Php/Factory/Argument.php b/src/phpDocumentor/Reflection/Php/Factory/Argument.php index 8c119eac..4ba4bc95 100644 --- a/src/phpDocumentor/Reflection/Php/Factory/Argument.php +++ b/src/phpDocumentor/Reflection/Php/Factory/Argument.php @@ -18,8 +18,11 @@ use phpDocumentor\Reflection\Php\ProjectFactoryStrategy; use phpDocumentor\Reflection\Php\StrategyContainer; use phpDocumentor\Reflection\PrettyPrinter; +use phpDocumentor\Reflection\Type; +use phpDocumentor\Reflection\TypeResolver; use phpDocumentor\Reflection\Types\Context; use PhpParser\Node\Expr\Variable; +use PhpParser\Node\NullableType; use PhpParser\Node\Param; use Webmozart\Assert\Assert; @@ -68,6 +71,23 @@ protected function doCreate($object, StrategyContainer $strategies, ?Context $co $default = $this->valueConverter->prettyPrintExpr($object->default); } - return new ArgumentDescriptor((string) $object->var->name, $default, $object->byRef, $object->variadic); + $argumentDescriptor = new ArgumentDescriptor((string) $object->var->name, $default, $object->byRef, $object->variadic); + + if (!empty($object->type)) { + $argumentDescriptor->addType($this->createType($object)); + } + + return $argumentDescriptor; + } + + private function createType(Param $arg, ?Context $context = null): Type + { + $typeResolver = new TypeResolver(); + $typeString = (string) $arg->type; + if ($arg->type instanceof NullableType) { + $typeString = '?' . $arg->type; + } + + return $typeResolver->resolve($typeString, $context); } } diff --git a/tests/component/ProjectCreationTest.php b/tests/component/ProjectCreationTest.php index 64be063b..969bf4c8 100644 --- a/tests/component/ProjectCreationTest.php +++ b/tests/component/ProjectCreationTest.php @@ -105,6 +105,7 @@ public function testWithNamespacedClass() ); $this->assertEquals('style', $methods['\\Luigi\\Pizza::__construct()']->getArguments()[0]->getName()); + $this->assertEquals([new Object_(new Fqsen('\\Luigi\\Pizza\Style'))], $methods['\\Luigi\\Pizza::__construct()']->getArguments()[0]->getTypes()); } public function testDocblockOfMethodIsProcessed()