Skip to content

Commit bb0c6c5

Browse files
authored
Skip internal PhpParser TokenPolyfill on DowngradePhpTokenRector (#239)
1 parent 829f969 commit bb0c6c5

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

rules/DowngradePhp80/Rector/StaticCall/DowngradePhpTokenRector.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use PhpParser\Node\Name;
1616
use PhpParser\Node\Scalar\Int_;
1717
use PHPStan\Type\ObjectType;
18+
use PHPStan\Type\Type;
1819
use Rector\Rector\AbstractRector;
1920
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
2021
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
@@ -89,6 +90,10 @@ private function refactorStaticCall(StaticCall $staticCall): ?FuncCall
8990
return null;
9091
}
9192

93+
if ($this->skipPhpParserInternalToken($this->getType($staticCall->class))) {
94+
return null;
95+
}
96+
9297
return new FuncCall(new Name('token_get_all'), $staticCall->args);
9398
}
9499

@@ -102,6 +107,10 @@ private function refactorMethodCall(MethodCall $methodCall): ?Ternary
102107
return null;
103108
}
104109

110+
if ($this->skipPhpParserInternalToken($this->getType($methodCall->var))) {
111+
return null;
112+
}
113+
105114
$isArrayFuncCall = new FuncCall(new Name('is_array'), [new Arg($methodCall->var)]);
106115
$arrayDimFetch = new ArrayDimFetch($methodCall->var, new Int_(0));
107116
$tokenGetNameFuncCall = new FuncCall(new Name('token_name'), [new Arg($arrayDimFetch)]);
@@ -120,6 +129,10 @@ private function refactorPropertyFetch(PropertyFetch $propertyFetch): ?Ternary
120129
return null;
121130
}
122131

132+
if ($this->skipPhpParserInternalToken($this->getType($propertyFetch->var))) {
133+
return null;
134+
}
135+
123136
$isArrayFuncCall = new FuncCall(new Name('is_array'), [new Arg($propertyFetch->var)]);
124137
$arrayDimFetch = new ArrayDimFetch(
125138
$propertyFetch->var,
@@ -128,4 +141,14 @@ private function refactorPropertyFetch(PropertyFetch $propertyFetch): ?Ternary
128141

129142
return new Ternary($isArrayFuncCall, $arrayDimFetch, $propertyFetch->var);
130143
}
144+
145+
private function skipPhpParserInternalToken(Type $type): bool
146+
{
147+
if ($type instanceof ObjectType) {
148+
return $type->isInstanceOf('PhpParser\Internal\TokenPolyfill')
149+
->yes();
150+
}
151+
152+
return false;
153+
}
131154
}

0 commit comments

Comments
 (0)