Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"phpdocumentor/reflection-common": "~2.2",
"phpstan/phpdoc-parser": "~1.23",
"voku/simple-cache": "~5.0",
"nikic/php-parser": "~4.18"
"nikic/php-parser": "^4.18 || ^5"
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nikic/php-parser is now allowed at ^5, but the codebase still calls APIs removed in v5 (notably PhpParser\Node\Name::getParts()). I found remaining call sites in src/voku/SimplePhpParser/Model/BasePHPElement.php, Model/PHPClass.php, Model/PHPInterface.php, Model/PHPEnum.php, Model/PHPConst.php, and Parsers/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., prefer Name::toString() or a small compat helper that uses getParts() when available and falls back to ->name/toString()).

Suggested change
"nikic/php-parser": "^4.18 || ^5"
"nikic/php-parser": "^4.18"

Copilot uses AI. Check for mistakes.
},
"require-dev": {
"phpunit/phpunit": "~9.6",
Expand Down
11 changes: 6 additions & 5 deletions src/voku/SimplePhpParser/Model/BasePHPElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '';
}
Expand All @@ -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;
}
}

Expand All @@ -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
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file still uses Name::getParts() (e.g., in getConstantFQN() and getFQN()), which was removed in php-parser v5. Even though prepareNode() now avoids Node::getLine(), these remaining getParts() calls will still cause fatal errors under v5; please update them to use ->toString() or a compat wrapper (similar to the approach taken in Utils::getPhpParserValueFromNode()).

Copilot uses AI. Check for mistakes.
Comment on lines +99 to +101
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getFQN() currently contains a var_dump($node->name); debug statement. This will emit output during normal library usage (breaking CLI output, JSON responses, etc.) and should be removed or replaced with a proper logger behind an explicit debug flag.

Copilot uses AI. Check for mistakes.
}
}
4 changes: 2 additions & 2 deletions src/voku/SimplePhpParser/Model/PHPClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function readObjectFromPhpNode($node, $dummy = null): self
$this->collectTags($node);

if (!empty($node->extends)) {
$classExtended = implode('\\', $node->extends->getParts());
$classExtended = $node->extends->toString();
/** @noinspection PhpSillyAssignmentInspection - hack for phpstan */
/** @var class-string $classExtended */
$classExtended = $classExtended;
Expand Down Expand Up @@ -121,7 +121,7 @@ public function readObjectFromPhpNode($node, $dummy = null): self

if (!empty($node->implements)) {
foreach ($node->implements as $interfaceObject) {
$interfaceFQN = implode('\\', $interfaceObject->getParts());
$interfaceFQN = $interfaceObject->toString();
/** @noinspection PhpSillyAssignmentInspection - hack for phpstan */
/** @var class-string $interfaceFQN */
$interfaceFQN = $interfaceFQN;
Expand Down
2 changes: 1 addition & 1 deletion src/voku/SimplePhpParser/Model/PHPConst.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ protected function getConstantFQN(NodeAbstract $node, string $nodeName): string
&&
$parentParentNode->name instanceof Name
) {
$namespace = '\\' . \implode('\\', $parentParentNode->name->getParts()) . '\\';
$namespace = '\\' . $parentParentNode->name->toString() . '\\';
} else {
$namespace = '';
}
Expand Down
2 changes: 1 addition & 1 deletion src/voku/SimplePhpParser/Model/PHPEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function readObjectFromPhpNode($node, $dummy = null): self

if (!empty($node->implements)) {
foreach ($node->implements as $interfaceObject) {
$interfaceFQN = \implode('\\', $interfaceObject->getParts());
$interfaceFQN = $interfaceObject->toString();
/** @noinspection PhpSillyAssignmentInspection - hack for phpstan */
/** @var class-string $interfaceFQN */
$interfaceFQN = $interfaceFQN;
Expand Down
2 changes: 1 addition & 1 deletion src/voku/SimplePhpParser/Model/PHPInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function readObjectFromPhpNode($node, $dummy = null): self

if (!empty($node->extends)) {
/** @var class-string $interfaceExtended */
$interfaceExtended = \implode('\\', $node->extends[0]->getParts());
$interfaceExtended = $node->extends[0]->toString();
$this->parentInterfaces[] = $interfaceExtended;
}

Expand Down
2 changes: 1 addition & 1 deletion src/voku/SimplePhpParser/Parsers/Helper/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public static function getPhpParserValueFromNode(
$node->value->name
) {
if ($node->value->name instanceof \PhpParser\Node\Name) {
$value = implode('\\', $node->value->name->getParts()) ?: $node->value->name->name;
$value = $node->value->name->toString();
} else {
$value = \is_string($node->value->name) ? $node->value->name : (string) $node->value->name;
}
Expand Down
2 changes: 1 addition & 1 deletion src/voku/SimplePhpParser/Parsers/PhpCodeParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public static function process(
ParserContainer $parserContainer,
ASTVisitor $visitor
) {
$parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7);
$parser = (new ParserFactory())->createForNewestSupportedVersion();

$errorHandler = new ParserErrorHandler();

Expand Down
Loading