diff --git a/rules/DowngradePhp80/Rector/StaticCall/DowngradePhpTokenRector.php b/rules/DowngradePhp80/Rector/StaticCall/DowngradePhpTokenRector.php index 512f11fb..bff597af 100644 --- a/rules/DowngradePhp80/Rector/StaticCall/DowngradePhpTokenRector.php +++ b/rules/DowngradePhp80/Rector/StaticCall/DowngradePhpTokenRector.php @@ -15,6 +15,7 @@ use PhpParser\Node\Name; use PhpParser\Node\Scalar\Int_; use PHPStan\Type\ObjectType; +use PHPStan\Type\Type; use Rector\Rector\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -89,6 +90,10 @@ private function refactorStaticCall(StaticCall $staticCall): ?FuncCall return null; } + if ($this->skipPhpParserInternalToken($this->getType($staticCall->class))) { + return null; + } + return new FuncCall(new Name('token_get_all'), $staticCall->args); } @@ -102,6 +107,10 @@ private function refactorMethodCall(MethodCall $methodCall): ?Ternary return null; } + if ($this->skipPhpParserInternalToken($this->getType($methodCall->var))) { + return null; + } + $isArrayFuncCall = new FuncCall(new Name('is_array'), [new Arg($methodCall->var)]); $arrayDimFetch = new ArrayDimFetch($methodCall->var, new Int_(0)); $tokenGetNameFuncCall = new FuncCall(new Name('token_name'), [new Arg($arrayDimFetch)]); @@ -120,6 +129,10 @@ private function refactorPropertyFetch(PropertyFetch $propertyFetch): ?Ternary return null; } + if ($this->skipPhpParserInternalToken($this->getType($propertyFetch->var))) { + return null; + } + $isArrayFuncCall = new FuncCall(new Name('is_array'), [new Arg($propertyFetch->var)]); $arrayDimFetch = new ArrayDimFetch( $propertyFetch->var, @@ -128,4 +141,14 @@ private function refactorPropertyFetch(PropertyFetch $propertyFetch): ?Ternary return new Ternary($isArrayFuncCall, $arrayDimFetch, $propertyFetch->var); } + + private function skipPhpParserInternalToken(Type $type): bool + { + if ($type instanceof ObjectType) { + return $type->isInstanceOf('PhpParser\Internal\TokenPolyfill') + ->yes(); + } + + return false; + } }