1515use PhpParser \Node \Name ;
1616use PhpParser \Node \Scalar \Int_ ;
1717use PHPStan \Type \ObjectType ;
18+ use PHPStan \Type \Type ;
1819use Rector \Rector \AbstractRector ;
1920use Symplify \RuleDocGenerator \ValueObject \CodeSample \CodeSample ;
2021use 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