phpDocumentor / phpDocumentor/Reflection
ReturnType of "PhpParser\Node\Name\FullyQualified" - but no leading backslash leads to FQN added to current namespace
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 125
- Forks
- 60
- Avg merge
- 2m
- Merged PRs (30d)
- 9
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.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at doCreate where getReturnType() is converted to a string and passed to TypeResolver::resolve(), then inspect how FullyQualified and Name instances are handled. Reproduce the namespace-duplication case described in the issue and confirm that resolving a fully qualified return type does not prepend the current namespace.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100