Skip to content

Commit

Permalink
Ast: PhpNode - fixed parsing of Foo::class in global namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
janpecha committed Jun 28, 2024
1 parent f5c6dad commit 1453551
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Ast/PhpNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ public static function parse(NodeParser $parser)
} elseif ($parser->isCurrent(T_NAMESPACE)) {
$child = NamespaceNode::parse($parser->createSubParser());

} elseif ($parser->isCurrent(T_DOUBLE_COLON)) { // static call or property/constant
$parser->consumeAsUnknowContent(T_DOUBLE_COLON);
$parser->tryConsumeAsUnknowContent(T_CLASS);

} elseif ($parser->isCurrent(T_USE)) {
$child = UseNode::parse($parser->createSubParser());

Expand Down
11 changes: 11 additions & 0 deletions tests/PhpSimpleAst/fixtures/Php.static.class-keyword.2.dump
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CzProject\PhpSimpleAst\Ast\PhpString
children: array (1)
| 0 => CzProject\PhpSimpleAst\Ast\PhpNode
| | openTag: '<?php\n'
| | children: array (1)
| | | 0 => CzProject\PhpSimpleAst\Ast\UnknowNode
| | | | content: string
| | | | | '\n
| | | | | echo \Foo\Bar::class;\n
| | | | | test(\Foo\Bar::class, 'Lorem ipsum');\n'
| | closeTag: null
4 changes: 4 additions & 0 deletions tests/PhpSimpleAst/fixtures/Php.static.class-keyword.2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php

echo \Foo\Bar::class;
test(\Foo\Bar::class, 'Lorem ipsum');

0 comments on commit 1453551

Please sign in to comment.