Open
Description
Something strange seems to happen here:
$object->getReturnType()
returns a object of PhpParser\Node\Name\FullyQualified
despite it's not fully qualified in the source. So far no big deal. But: the string conversion does not contain a leading backslash.
protected function doCreate($object, StrategyContainer $strategies, ?Context $context = null)
{
$docBlock = $this->createDocBlock($strategies, $object->getDocComment(), $context);
$returnType = null;
if ($object->getReturnType() !== null) {
$typeResolver = new TypeResolver();
if ($object->getReturnType() instanceof NullableType) {
$typeString = '?' . $object->getReturnType()->type;
} else {
$typeString = (string) $object->getReturnType();
}
$returnType = $typeResolver->resolve($typeString, $context);
The subsequent call of $typeResolver->resolve($typeString, $context);
then leads to a concatination of the namespace of the file with the (not wellformed) FQN (e.g. \My\Current\Namespace\MyCurrent\Namespace\Class)
I did not tried it yet, but it might be enough to make sure that the string contains a leading backslash:
if (($object instanceof \PhpParser\Node\Name\FullyQualified) && ($typeString[0] !== '\\' ) {
$typeString = '\\' .$typeString;
}
Update:
Checking on instance of \PhpParser\Node\Name and $returnType->isFullyQualified() might be the even cleaner approach.
Metadata
Metadata
Assignees
Labels
No labels