From 1453551798e8b82293a937f3815f0b00db419f23 Mon Sep 17 00:00:00 2001 From: Jan Pecha Date: Fri, 28 Jun 2024 10:00:42 +0200 Subject: [PATCH] Ast: PhpNode - fixed parsing of Foo::class in global namespace --- src/Ast/PhpNode.php | 4 ++++ .../fixtures/Php.static.class-keyword.2.dump | 11 +++++++++++ .../fixtures/Php.static.class-keyword.2.php | 4 ++++ 3 files changed, 19 insertions(+) create mode 100644 tests/PhpSimpleAst/fixtures/Php.static.class-keyword.2.dump create mode 100644 tests/PhpSimpleAst/fixtures/Php.static.class-keyword.2.php diff --git a/src/Ast/PhpNode.php b/src/Ast/PhpNode.php index e8a567e..2e7e89a 100644 --- a/src/Ast/PhpNode.php +++ b/src/Ast/PhpNode.php @@ -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()); diff --git a/tests/PhpSimpleAst/fixtures/Php.static.class-keyword.2.dump b/tests/PhpSimpleAst/fixtures/Php.static.class-keyword.2.dump new file mode 100644 index 0000000..0c3b858 --- /dev/null +++ b/tests/PhpSimpleAst/fixtures/Php.static.class-keyword.2.dump @@ -0,0 +1,11 @@ +CzProject\PhpSimpleAst\Ast\PhpString + children: array (1) + | 0 => CzProject\PhpSimpleAst\Ast\PhpNode + | | openTag: ' CzProject\PhpSimpleAst\Ast\UnknowNode + | | | | content: string + | | | | | '\n + | | | | | echo \Foo\Bar::class;\n + | | | | | test(\Foo\Bar::class, 'Lorem ipsum');\n' + | | closeTag: null diff --git a/tests/PhpSimpleAst/fixtures/Php.static.class-keyword.2.php b/tests/PhpSimpleAst/fixtures/Php.static.class-keyword.2.php new file mode 100644 index 0000000..08b537b --- /dev/null +++ b/tests/PhpSimpleAst/fixtures/Php.static.class-keyword.2.php @@ -0,0 +1,4 @@ +