diff --git a/rules/Php70/Rector/MethodCall/ThisCallOnStaticMethodToStaticCallRector.php b/rules/Php70/Rector/MethodCall/ThisCallOnStaticMethodToStaticCallRector.php index 0b0baf262a6..ed6d85cd07d 100644 --- a/rules/Php70/Rector/MethodCall/ThisCallOnStaticMethodToStaticCallRector.php +++ b/rules/Php70/Rector/MethodCall/ThisCallOnStaticMethodToStaticCallRector.php @@ -8,7 +8,9 @@ use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Expr\StaticCall; use PhpParser\Node\Expr\Variable; use PhpParser\Node\Identifier; +use PhpParser\Node\Scalar\Encapsed; use PhpParser\Node\Stmt\Class_; +use PhpParser\NodeTraverser; use PHPStan\Analyser\Scope; use PHPStan\Reflection\ClassReflection; use PHPStan\Reflection\Php\PhpMethodReflection; @@ -36,6 +38,10 @@ final class ThisCallOnStaticMethodToStaticCallRector extends AbstractScopeAwareR * @var \Rector\Reflection\ReflectionResolver */ private $reflectionResolver; + /** + * @var bool + */ + private $hasChanged = \false; public function __construct(StaticAnalyzer $staticAnalyzer, ReflectionResolver $reflectionResolver) { $this->staticAnalyzer = $staticAnalyzer; @@ -95,8 +101,19 @@ CODE_SAMPLE if ($classReflection->isSubclassOf('PHPUnit\\Framework\\TestCase')) { return null; } - $hasChanged = \false; - $this->traverseNodesWithCallable($node, function (Node $subNode) use($node, $classReflection, &$hasChanged) : ?StaticCall { + $this->hasChanged = \false; + $this->processThisToStatic($node, $classReflection); + if ($this->hasChanged) { + return $node; + } + return null; + } + private function processThisToStatic(Class_ $class, ClassReflection $classReflection) : void + { + $this->traverseNodesWithCallable($class, function (Node $subNode) use($class, $classReflection) { + if ($subNode instanceof Encapsed) { + return NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN; + } if (!$subNode instanceof MethodCall) { return null; } @@ -113,21 +130,17 @@ CODE_SAMPLE if ($methodName === null) { return null; } - $isStaticMethod = $this->staticAnalyzer->isStaticMethod($classReflection, $methodName, $node); + $isStaticMethod = $this->staticAnalyzer->isStaticMethod($classReflection, $methodName, $class); if (!$isStaticMethod) { return null; } if ($subNode->isFirstClassCallable()) { return null; } - $hasChanged = \true; + $this->hasChanged = \true; $objectReference = $this->resolveClassSelf($classReflection, $subNode); return $this->nodeFactory->createStaticCall($objectReference, $methodName, $subNode->args); }); - if ($hasChanged) { - return $node; - } - return null; } /** * @return ObjectReference::STATIC|ObjectReference::SELF diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index 201be18f4bb..8b93c30be85 100644 --- a/src/Application/VersionResolver.php +++ b/src/Application/VersionResolver.php @@ -19,12 +19,12 @@ final class VersionResolver * @api * @var string */ - public const PACKAGE_VERSION = '0.19.2'; + public const PACKAGE_VERSION = '7e2495e5f572bb566a845a0e1a6329cf141f872d'; /** * @api * @var string */ - public const RELEASE_DATE = '2024-01-18 21:39:30'; + public const RELEASE_DATE = '2024-01-19 21:03:24'; /** * @var int */