Skip to content

Commit ae4c0b7

Browse files
committed
Updated Rector to commit 72cdbd0613318b797455deba64ebe6358d58af42
rectorphp/rector-src@72cdbd0 [CodeQuality][Php70] Handle LocallyCalledStaticMethodToNonStaticRector + ThisCallOnStaticMethodToStaticCallRector must change both method and caller (#5196)
1 parent 17928ec commit ae4c0b7

File tree

3 files changed

+24
-14
lines changed

3 files changed

+24
-14
lines changed

packages/NodeCollector/StaticAnalyzer.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,27 @@
33
declare (strict_types=1);
44
namespace Rector\NodeCollector;
55

6+
use PhpParser\Node\Stmt\Class_;
7+
use PhpParser\Node\Stmt\ClassMethod;
68
use PHPStan\PhpDoc\ResolvedPhpDocBlock;
79
use PHPStan\Reflection\ClassReflection;
810
use Rector\Core\Util\StringUtils;
911
final class StaticAnalyzer
1012
{
11-
public function isStaticMethod(ClassReflection $classReflection, string $methodName) : bool
13+
public function isStaticMethod(ClassReflection $classReflection, string $methodName, ?Class_ $class = null) : bool
1214
{
1315
if ($classReflection->hasNativeMethod($methodName)) {
1416
$extendedMethodReflection = $classReflection->getNativeMethod($methodName);
1517
if ($extendedMethodReflection->isStatic()) {
16-
return \true;
18+
// use cached ClassReflection
19+
if (!$class instanceof Class_) {
20+
return \true;
21+
}
22+
// use non-cached Class_
23+
$classMethod = $class->getMethod($methodName);
24+
if ($classMethod instanceof ClassMethod && $classMethod->isStatic()) {
25+
return \true;
26+
}
1727
}
1828
}
1929
// could be static in doc type magic

rules/Php70/Rector/MethodCall/ThisCallOnStaticMethodToStaticCallRector.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -96,33 +96,33 @@ public function refactorWithScope(Node $node, Scope $scope) : ?Node
9696
return null;
9797
}
9898
$hasChanged = \false;
99-
$this->traverseNodesWithCallable($node, function (Node $node) use($classReflection, &$hasChanged) : ?StaticCall {
100-
if (!$node instanceof MethodCall) {
99+
$this->traverseNodesWithCallable($node, function (Node $subNode) use($node, $classReflection, &$hasChanged) : ?StaticCall {
100+
if (!$subNode instanceof MethodCall) {
101101
return null;
102102
}
103-
if (!$node->var instanceof Variable) {
103+
if (!$subNode->var instanceof Variable) {
104104
return null;
105105
}
106-
if (!$this->nodeNameResolver->isName($node->var, 'this')) {
106+
if (!$this->nodeNameResolver->isName($subNode->var, 'this')) {
107107
return null;
108108
}
109-
if (!$node->name instanceof Identifier) {
109+
if (!$subNode->name instanceof Identifier) {
110110
return null;
111111
}
112-
$methodName = $this->getName($node->name);
112+
$methodName = $this->getName($subNode->name);
113113
if ($methodName === null) {
114114
return null;
115115
}
116-
$isStaticMethod = $this->staticAnalyzer->isStaticMethod($classReflection, $methodName);
116+
$isStaticMethod = $this->staticAnalyzer->isStaticMethod($classReflection, $methodName, $node);
117117
if (!$isStaticMethod) {
118118
return null;
119119
}
120-
if ($node->isFirstClassCallable()) {
120+
if ($subNode->isFirstClassCallable()) {
121121
return null;
122122
}
123123
$hasChanged = \true;
124-
$objectReference = $this->resolveClassSelf($classReflection, $node);
125-
return $this->nodeFactory->createStaticCall($objectReference, $methodName, $node->args);
124+
$objectReference = $this->resolveClassSelf($classReflection, $subNode);
125+
return $this->nodeFactory->createStaticCall($objectReference, $methodName, $subNode->args);
126126
});
127127
if ($hasChanged) {
128128
return $node;

src/Application/VersionResolver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ final class VersionResolver
1919
* @api
2020
* @var string
2121
*/
22-
public const PACKAGE_VERSION = '29265cacf4b81261cb33885acaaa4edcb5885dd4';
22+
public const PACKAGE_VERSION = '72cdbd0613318b797455deba64ebe6358d58af42';
2323
/**
2424
* @api
2525
* @var string
2626
*/
27-
public const RELEASE_DATE = '2023-10-25 15:01:10';
27+
public const RELEASE_DATE = '2023-10-26 14:07:55';
2828
/**
2929
* @var int
3030
*/

0 commit comments

Comments
 (0)