Updated Rector to commit 72cdbd0613318b797455deba64ebe6358d58af42

72cdbd0613 [CodeQuality][Php70] Handle LocallyCalledStaticMethodToNonStaticRector + ThisCallOnStaticMethodToStaticCallRector must change both method and caller (#5196)
This commit is contained in:
Tomas Votruba 2023-10-26 07:11:41 +00:00
parent 17928ec6ab
commit ae4c0b72cb
3 changed files with 24 additions and 14 deletions

View File

@ -3,17 +3,27 @@
declare (strict_types=1);
namespace Rector\NodeCollector;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
use PHPStan\PhpDoc\ResolvedPhpDocBlock;
use PHPStan\Reflection\ClassReflection;
use Rector\Core\Util\StringUtils;
final class StaticAnalyzer
{
public function isStaticMethod(ClassReflection $classReflection, string $methodName) : bool
public function isStaticMethod(ClassReflection $classReflection, string $methodName, ?Class_ $class = null) : bool
{
if ($classReflection->hasNativeMethod($methodName)) {
$extendedMethodReflection = $classReflection->getNativeMethod($methodName);
if ($extendedMethodReflection->isStatic()) {
return \true;
// use cached ClassReflection
if (!$class instanceof Class_) {
return \true;
}
// use non-cached Class_
$classMethod = $class->getMethod($methodName);
if ($classMethod instanceof ClassMethod && $classMethod->isStatic()) {
return \true;
}
}
}
// could be static in doc type magic

View File

@ -96,33 +96,33 @@ CODE_SAMPLE
return null;
}
$hasChanged = \false;
$this->traverseNodesWithCallable($node, function (Node $node) use($classReflection, &$hasChanged) : ?StaticCall {
if (!$node instanceof MethodCall) {
$this->traverseNodesWithCallable($node, function (Node $subNode) use($node, $classReflection, &$hasChanged) : ?StaticCall {
if (!$subNode instanceof MethodCall) {
return null;
}
if (!$node->var instanceof Variable) {
if (!$subNode->var instanceof Variable) {
return null;
}
if (!$this->nodeNameResolver->isName($node->var, 'this')) {
if (!$this->nodeNameResolver->isName($subNode->var, 'this')) {
return null;
}
if (!$node->name instanceof Identifier) {
if (!$subNode->name instanceof Identifier) {
return null;
}
$methodName = $this->getName($node->name);
$methodName = $this->getName($subNode->name);
if ($methodName === null) {
return null;
}
$isStaticMethod = $this->staticAnalyzer->isStaticMethod($classReflection, $methodName);
$isStaticMethod = $this->staticAnalyzer->isStaticMethod($classReflection, $methodName, $node);
if (!$isStaticMethod) {
return null;
}
if ($node->isFirstClassCallable()) {
if ($subNode->isFirstClassCallable()) {
return null;
}
$hasChanged = \true;
$objectReference = $this->resolveClassSelf($classReflection, $node);
return $this->nodeFactory->createStaticCall($objectReference, $methodName, $node->args);
$objectReference = $this->resolveClassSelf($classReflection, $subNode);
return $this->nodeFactory->createStaticCall($objectReference, $methodName, $subNode->args);
});
if ($hasChanged) {
return $node;

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '29265cacf4b81261cb33885acaaa4edcb5885dd4';
public const PACKAGE_VERSION = '72cdbd0613318b797455deba64ebe6358d58af42';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2023-10-25 15:01:10';
public const RELEASE_DATE = '2023-10-26 14:07:55';
/**
* @var int
*/