Updated Rector to commit 7e2495e5f572bb566a845a0e1a6329cf141f872d

7e2495e5f5 [Php70] Skip inside Encapsed on ThisCallOnStaticMethodToStaticCallRector (#5481)
This commit is contained in:
Tomas Votruba 2024-01-19 14:05:32 +00:00
parent bc96a99895
commit 6cacf30624
2 changed files with 23 additions and 10 deletions

View File

@ -8,7 +8,9 @@ use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\StaticCall; use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Expr\Variable; use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Identifier; use PhpParser\Node\Identifier;
use PhpParser\Node\Scalar\Encapsed;
use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\Class_;
use PhpParser\NodeTraverser;
use PHPStan\Analyser\Scope; use PHPStan\Analyser\Scope;
use PHPStan\Reflection\ClassReflection; use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\Php\PhpMethodReflection; use PHPStan\Reflection\Php\PhpMethodReflection;
@ -36,6 +38,10 @@ final class ThisCallOnStaticMethodToStaticCallRector extends AbstractScopeAwareR
* @var \Rector\Reflection\ReflectionResolver * @var \Rector\Reflection\ReflectionResolver
*/ */
private $reflectionResolver; private $reflectionResolver;
/**
* @var bool
*/
private $hasChanged = \false;
public function __construct(StaticAnalyzer $staticAnalyzer, ReflectionResolver $reflectionResolver) public function __construct(StaticAnalyzer $staticAnalyzer, ReflectionResolver $reflectionResolver)
{ {
$this->staticAnalyzer = $staticAnalyzer; $this->staticAnalyzer = $staticAnalyzer;
@ -95,8 +101,19 @@ CODE_SAMPLE
if ($classReflection->isSubclassOf('PHPUnit\\Framework\\TestCase')) { if ($classReflection->isSubclassOf('PHPUnit\\Framework\\TestCase')) {
return null; return null;
} }
$hasChanged = \false; $this->hasChanged = \false;
$this->traverseNodesWithCallable($node, function (Node $subNode) use($node, $classReflection, &$hasChanged) : ?StaticCall { $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) { if (!$subNode instanceof MethodCall) {
return null; return null;
} }
@ -113,21 +130,17 @@ CODE_SAMPLE
if ($methodName === null) { if ($methodName === null) {
return null; return null;
} }
$isStaticMethod = $this->staticAnalyzer->isStaticMethod($classReflection, $methodName, $node); $isStaticMethod = $this->staticAnalyzer->isStaticMethod($classReflection, $methodName, $class);
if (!$isStaticMethod) { if (!$isStaticMethod) {
return null; return null;
} }
if ($subNode->isFirstClassCallable()) { if ($subNode->isFirstClassCallable()) {
return null; return null;
} }
$hasChanged = \true; $this->hasChanged = \true;
$objectReference = $this->resolveClassSelf($classReflection, $subNode); $objectReference = $this->resolveClassSelf($classReflection, $subNode);
return $this->nodeFactory->createStaticCall($objectReference, $methodName, $subNode->args); return $this->nodeFactory->createStaticCall($objectReference, $methodName, $subNode->args);
}); });
if ($hasChanged) {
return $node;
}
return null;
} }
/** /**
* @return ObjectReference::STATIC|ObjectReference::SELF * @return ObjectReference::STATIC|ObjectReference::SELF

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api * @api
* @var string * @var string
*/ */
public const PACKAGE_VERSION = '0.19.2'; public const PACKAGE_VERSION = '7e2495e5f572bb566a845a0e1a6329cf141f872d';
/** /**
* @api * @api
* @var string * @var string
*/ */
public const RELEASE_DATE = '2024-01-18 21:39:30'; public const RELEASE_DATE = '2024-01-19 21:03:24';
/** /**
* @var int * @var int
*/ */