Skip to content
Merged
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
23 changes: 23 additions & 0 deletions rules/DowngradePhp80/Rector/StaticCall/DowngradePhpTokenRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand All @@ -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)]);
Expand All @@ -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,
Expand All @@ -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;
}
}
Loading