Skip to content

Commit 5e5db15

Browse files
committed
Fix issue with self reference constants
1 parent 046ade6 commit 5e5db15

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
use PhpParser\Node\Name;
2525
use PhpParser\PrettyPrinter\Standard;
2626

27+
use function ltrim;
28+
2729
final class ExpressionPrinter extends Standard
2830
{
2931
/** @var array<string, Fqsen|Type> */
@@ -93,7 +95,7 @@ protected function pExpr_ClassConstFetch(Expr\ClassConstFetch $node): string
9395

9496
$placeholder = Expression::generatePlaceholder((string) $renderedName);
9597
$this->parts[$placeholder] = new Fqsen(
96-
$className . '::' . $renderedName,
98+
'\\' . ltrim((string) $className, '\\') . '::' . $renderedName,
9799
);
98100

99101
return $placeholder;

tests/unit/phpDocumentor/Reflection/Php/Expression/ExpressionPrinterTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ public static function argumentProvider(): array
6363
'{{ PHPDOCe54b7c24dd0f847c3193039223751b3d }}' => new Fqsen('\MyClass::SOME_CONST'),
6464
],
6565
],
66+
'selfConstantDefault' => [
67+
'code' => '<?php function foo(MyClass $arg = self::SOME_CONST) {}',
68+
'expectedExpression' => '{{ PHPDOCe54b7c24dd0f847c3193039223751b3d }}',
69+
'expectedParts' => [
70+
'{{ PHPDOCe54b7c24dd0f847c3193039223751b3d }}' => new Fqsen('\self::SOME_CONST'),
71+
],
72+
],
6673
'stringDefault' => [
6774
'code' => '<?php function foo(string $arg = \'hello\') {}',
6875
'expectedExpression' => "'hello'",

0 commit comments

Comments
 (0)