-
-
Notifications
You must be signed in to change notification settings - Fork 6
Add php-parser v5 compatibility (^4.18 || ^5) #77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,7 +55,7 @@ protected function getConstantFQN(NodeAbstract $node, string $nodeName): string | |
| && | ||
| $parent->name instanceof Name | ||
| ) { | ||
| $namespace = '\\' . \implode('\\', $parent->name->getParts()) . '\\'; | ||
| $namespace = '\\' . $parent->name->toString() . '\\'; | ||
| } else { | ||
| $namespace = ''; | ||
| } | ||
|
|
@@ -81,10 +81,9 @@ protected static function getFQN($node): string | |
| \property_exists($node, 'namespacedName') | ||
| ) { | ||
| if ($node->namespacedName) { | ||
| $fqn = \implode('\\', $node->namespacedName->getParts()); | ||
| $fqn = $node->namespacedName->toString(); | ||
| } elseif (\property_exists($node, 'name') && $node->name) { | ||
| var_dump($node->name); | ||
| $fqn = $node->name->name; | ||
| $fqn = $node->name instanceof Name ? $node->name->toString() : (string) $node->name; | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -97,6 +96,8 @@ protected static function getFQN($node): string | |
|
|
||
| protected function prepareNode(Node $node): void | ||
| { | ||
| $this->line = $node->getLine(); | ||
| $this->line = method_exists($node, 'getStartLine') | ||
| ? $node->getStartLine() | ||
| : $node->getLine(); // @phpstan-ignore-line getLine() was removed in PHP-Parser v5 | ||
|
Comment on lines
+99
to
+101
|
||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nikic/php-parseris now allowed at^5, but the codebase still calls APIs removed in v5 (notablyPhpParser\Node\Name::getParts()). I found remaining call sites insrc/voku/SimplePhpParser/Model/BasePHPElement.php,Model/PHPClass.php,Model/PHPInterface.php,Model/PHPEnum.php,Model/PHPConst.php, andParsers/Visitors/ASTVisitor.php. With php-parser v5 installed these will fatal at runtime, so the constraint change should be paired with updating those usages (e.g., preferName::toString()or a small compat helper that usesgetParts()when available and falls back to->name/toString()).