Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/phpDocumentor/Reflection/NodeVisitor/ElementNameResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace phpDocumentor\Reflection\NodeVisitor;

use InvalidArgumentException;
use Override;
use phpDocumentor\Reflection\Fqsen;
use PhpParser\Node;
Expand Down Expand Up @@ -118,14 +119,13 @@ public function enterNode(Node $node): int|null
case Function_::class:
$this->parts->push($node->name . '()');
$this->setFqsen($node);

return NodeTraverser::DONT_TRAVERSE_CHILDREN;
break;

case ClassMethod::class:
$this->parts->push('::' . $node->name . '()');
$this->setFqsen($node);

return NodeTraverser::DONT_TRAVERSE_CHILDREN;
break;

case ClassConst::class:
$this->parts->push('::');
Expand Down Expand Up @@ -172,7 +172,12 @@ private function buildName(): string

private function setFqsen(Node $node): void
{
$fqsen = new Fqsen($this->buildName());
$node->setAttribute('fqsen', $fqsen);
try {
$fqsen = new Fqsen($this->buildName());
$node->setAttribute('fqsen', $fqsen);
} catch (InvalidArgumentException) {
// If the name is invalid, we do not set the fqsen attribute. This allows us to continue processing
// the rest of the nodes without interruption.
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,13 @@ protected function pExpr_ClassConstFetch(Expr\ClassConstFetch $node): string
return $placeholder;
}

// protected function pExpr_ConstFetch(Expr\ConstFetch $node): string
// {
// $className = parent::pName($node->name);
// $className = $this->typeResolver->resolve($className, $this->context);
// return 'trst';
// }

/** @return array<string, Fqsen|Type> */
public function getParts(): array
{
Expand Down
14 changes: 12 additions & 2 deletions tests/integration/ProjectCreationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,12 +275,22 @@ public function testFunctionContantDefaultIsResolved() : void

self::assertEquals(
new Expression(
'{{ PHPDOCa8cfde6331bd59eb2ac96f8911c4b666 }}',
'{{ PHPDOC0de51a5acf75f22ec3c4a9568981d703 }}',
[
'{{ PHPDOCa8cfde6331bd59eb2ac96f8911c4b666 }}' => new Object_(),
'{{ PHPDOC0de51a5acf75f22ec3c4a9568981d703 }}' => new Fqsen('\OBJECT'),
],
),
$functions['\bar()']->getArguments()[0]->getDefault()
);

self::assertEquals(
new Expression(
'{{ PHPDOC342481e8fedbe60c956b14c1f80f5274 }}',
[
'{{ PHPDOC342481e8fedbe60c956b14c1f80f5274 }}' => new Fqsen('\Acme\FOO'),
],
),
$functions['\bar2()']->getArguments()[0]->getDefault()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

use Acme\Plugin;

use const Acme\FOO;

function foo( $output = Plugin::class ) {}

function bar( $output = OBJECT ) {}

function bar2( $output = FOO ) {}
Loading