Skip to content

Commit 70254fa

Browse files
authored
Merge pull request #738 from phpDocumentor/fix/element-name-resolving
Fix default value name resolving
2 parents acdfaeb + 8ed671e commit 70254fa

4 files changed

Lines changed: 33 additions & 7 deletions

File tree

src/phpDocumentor/Reflection/NodeVisitor/ElementNameResolver.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace phpDocumentor\Reflection\NodeVisitor;
1515

16+
use InvalidArgumentException;
1617
use Override;
1718
use phpDocumentor\Reflection\Fqsen;
1819
use PhpParser\Node;
@@ -118,14 +119,13 @@ public function enterNode(Node $node): int|null
118119
case Function_::class:
119120
$this->parts->push($node->name . '()');
120121
$this->setFqsen($node);
121-
122-
return NodeTraverser::DONT_TRAVERSE_CHILDREN;
122+
break;
123123

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

128-
return NodeTraverser::DONT_TRAVERSE_CHILDREN;
128+
break;
129129

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

173173
private function setFqsen(Node $node): void
174174
{
175-
$fqsen = new Fqsen($this->buildName());
176-
$node->setAttribute('fqsen', $fqsen);
175+
try {
176+
$fqsen = new Fqsen($this->buildName());
177+
$node->setAttribute('fqsen', $fqsen);
178+
} catch (InvalidArgumentException) {
179+
// If the name is invalid, we do not set the fqsen attribute. This allows us to continue processing
180+
// the rest of the nodes without interruption.
181+
}
177182
}
178183
}

src/phpDocumentor/Reflection/Php/Expression/ExpressionPrinter.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,13 @@ protected function pExpr_ClassConstFetch(Expr\ClassConstFetch $node): string
104104
return $placeholder;
105105
}
106106

107+
// protected function pExpr_ConstFetch(Expr\ConstFetch $node): string
108+
// {
109+
// $className = parent::pName($node->name);
110+
// $className = $this->typeResolver->resolve($className, $this->context);
111+
// return 'trst';
112+
// }
113+
107114
/** @return array<string, Fqsen|Type> */
108115
public function getParts(): array
109116
{

tests/integration/ProjectCreationTest.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,12 +275,22 @@ public function testFunctionContantDefaultIsResolved() : void
275275

276276
self::assertEquals(
277277
new Expression(
278-
'{{ PHPDOCa8cfde6331bd59eb2ac96f8911c4b666 }}',
278+
'{{ PHPDOC0de51a5acf75f22ec3c4a9568981d703 }}',
279279
[
280-
'{{ PHPDOCa8cfde6331bd59eb2ac96f8911c4b666 }}' => new Object_(),
280+
'{{ PHPDOC0de51a5acf75f22ec3c4a9568981d703 }}' => new Fqsen('\OBJECT'),
281281
],
282282
),
283283
$functions['\bar()']->getArguments()[0]->getDefault()
284284
);
285+
286+
self::assertEquals(
287+
new Expression(
288+
'{{ PHPDOC342481e8fedbe60c956b14c1f80f5274 }}',
289+
[
290+
'{{ PHPDOC342481e8fedbe60c956b14c1f80f5274 }}' => new Fqsen('\Acme\FOO'),
291+
],
292+
),
293+
$functions['\bar2()']->getArguments()[0]->getDefault()
294+
);
285295
}
286296
}

tests/integration/data/GlobalFiles/function_constant_default.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
use Acme\Plugin;
44

5+
use const Acme\FOO;
6+
57
function foo( $output = Plugin::class ) {}
68

79
function bar( $output = OBJECT ) {}
10+
11+
function bar2( $output = FOO ) {}

0 commit comments

Comments
 (0)