diff --git a/src/phpDocumentor/Reflection/NodeVisitor/ElementNameResolver.php b/src/phpDocumentor/Reflection/NodeVisitor/ElementNameResolver.php index 2139d709..fe08f74d 100644 --- a/src/phpDocumentor/Reflection/NodeVisitor/ElementNameResolver.php +++ b/src/phpDocumentor/Reflection/NodeVisitor/ElementNameResolver.php @@ -13,6 +13,7 @@ namespace phpDocumentor\Reflection\NodeVisitor; +use InvalidArgumentException; use Override; use phpDocumentor\Reflection\Fqsen; use PhpParser\Node; @@ -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('::'); @@ -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. + } } } diff --git a/src/phpDocumentor/Reflection/Php/Expression/ExpressionPrinter.php b/src/phpDocumentor/Reflection/Php/Expression/ExpressionPrinter.php index 5e9162ec..a308a93c 100644 --- a/src/phpDocumentor/Reflection/Php/Expression/ExpressionPrinter.php +++ b/src/phpDocumentor/Reflection/Php/Expression/ExpressionPrinter.php @@ -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 */ public function getParts(): array { diff --git a/tests/integration/ProjectCreationTest.php b/tests/integration/ProjectCreationTest.php index cb36a929..cbb56455 100644 --- a/tests/integration/ProjectCreationTest.php +++ b/tests/integration/ProjectCreationTest.php @@ -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() + ); } } diff --git a/tests/integration/data/GlobalFiles/function_constant_default.php b/tests/integration/data/GlobalFiles/function_constant_default.php index 685a0d03..b2fbd850 100644 --- a/tests/integration/data/GlobalFiles/function_constant_default.php +++ b/tests/integration/data/GlobalFiles/function_constant_default.php @@ -2,6 +2,10 @@ use Acme\Plugin; +use const Acme\FOO; + function foo( $output = Plugin::class ) {} function bar( $output = OBJECT ) {} + +function bar2( $output = FOO ) {}