Skip to content

Commit 71572c7

Browse files
authored
Merge pull request #131 from jaapio/feature/param-type
Add parameter type resolving
2 parents 5231473 + 2fc8570 commit 71572c7

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

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

+22-1
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,24 @@ 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+
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);
7293
}
7394
}

tests/component/ProjectCreationTest.php

+1
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)