Skip to content

Commit 0cde2cd

Browse files
committed
Add parameter type resolving
1 parent 5231473 commit 0cde2cd

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@
1818
use phpDocumentor\Reflection\Php\ProjectFactoryStrategy;
1919
use phpDocumentor\Reflection\Php\StrategyContainer;
2020
use phpDocumentor\Reflection\PrettyPrinter;
21+
use phpDocumentor\Reflection\Type;
22+
use phpDocumentor\Reflection\TypeResolver;
2123
use phpDocumentor\Reflection\Types\Context;
2224
use PhpParser\Node\Expr\Variable;
25+
use PhpParser\Node\NullableType;
2326
use PhpParser\Node\Param;
2427
use Webmozart\Assert\Assert;
2528

@@ -68,6 +71,23 @@ protected function doCreate($object, StrategyContainer $strategies, ?Context $co
6871
$default = $this->valueConverter->prettyPrintExpr($object->default);
6972
}
7073

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+
$typeString = (string) $arg->type;
87+
if ($arg->type instanceof NullableType) {
88+
$typeString = '?' . $arg->type;
89+
}
90+
91+
return $typeResolver->resolve($typeString, $context);
7292
}
7393
}

tests/component/ProjectCreationTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ public function testWithNamespacedClass()
105105
);
106106

107107
$this->assertEquals('style', $methods['\\Luigi\\Pizza::__construct()']->getArguments()[0]->getName());
108+
$this->assertEquals([new Object_(new Fqsen('\\Luigi\\Pizza\Style'))], $methods['\\Luigi\\Pizza::__construct()']->getArguments()[0]->getTypes());
108109
}
109110

110111
public function testDocblockOfMethodIsProcessed()

0 commit comments

Comments
 (0)