website/errors/phpParser.classRenamed.md
<?php declare(strict_types = 1);
use PhpParser\Node;
use PHPStan\Analyser\Scope;
use PHPStan\Rules\Rule;
/** @implements Rule<Node> */
class MyRule implements Rule
{
public function getNodeType(): string
{
return \PhpParser\Node\Expr\ArrayItem::class;
}
public function processNode(Node $node, Scope $scope): array
{
return [];
}
}
The code references a PHP-Parser class name that was renamed in PHP-Parser v5. PHPStan uses PHP-Parser v5, where several node classes were moved to new locations. Using the old class names will cause errors because these classes no longer exist under their original names.
The renamed classes include:
PhpParser\Node\Scalar\LNumber -> PhpParser\Node\Scalar\Int_PhpParser\Node\Scalar\DNumber -> PhpParser\Node\Scalar\Float_PhpParser\Node\Scalar\Encapsed -> PhpParser\Node\Scalar\InterpolatedStringPhpParser\Node\Scalar\EncapsedStringPart -> PhpParser\Node\InterpolatedStringPartPhpParser\Node\Expr\ArrayItem -> PhpParser\Node\ArrayItemPhpParser\Node\Expr\ClosureUse -> PhpParser\Node\ClosureUsePhpParser\Node\Stmt\DeclareDeclare -> PhpParser\Node\DeclareItemPhpParser\Node\Stmt\PropertyProperty -> PhpParser\Node\PropertyItemPhpParser\Node\Stmt\StaticVar -> PhpParser\Node\StaticVarPhpParser\Node\Stmt\UseUse -> PhpParser\Node\UseItemReplace the old class name with the new one from PHP-Parser v5:
/** @implements Rule<Node> */
class MyRule implements Rule
{
public function getNodeType(): string
{
- return \PhpParser\Node\Expr\ArrayItem::class;
+ return \PhpParser\Node\ArrayItem::class;
}
public function processNode(Node $node, Scope $scope): array
{
return [];
}
}
See the PHP-Parser v5 upgrade guide for the full list of renamed classes.