mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-22 02:52:23 +00:00
Updated Rector to commit 72cdbd0613318b797455deba64ebe6358d58af42
72cdbd0613
[CodeQuality][Php70] Handle LocallyCalledStaticMethodToNonStaticRector + ThisCallOnStaticMethodToStaticCallRector must change both method and caller (#5196)
This commit is contained in:
parent
17928ec6ab
commit
ae4c0b72cb
|
@ -3,17 +3,27 @@
|
||||||
declare (strict_types=1);
|
declare (strict_types=1);
|
||||||
namespace Rector\NodeCollector;
|
namespace Rector\NodeCollector;
|
||||||
|
|
||||||
|
use PhpParser\Node\Stmt\Class_;
|
||||||
|
use PhpParser\Node\Stmt\ClassMethod;
|
||||||
use PHPStan\PhpDoc\ResolvedPhpDocBlock;
|
use PHPStan\PhpDoc\ResolvedPhpDocBlock;
|
||||||
use PHPStan\Reflection\ClassReflection;
|
use PHPStan\Reflection\ClassReflection;
|
||||||
use Rector\Core\Util\StringUtils;
|
use Rector\Core\Util\StringUtils;
|
||||||
final class StaticAnalyzer
|
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)) {
|
if ($classReflection->hasNativeMethod($methodName)) {
|
||||||
$extendedMethodReflection = $classReflection->getNativeMethod($methodName);
|
$extendedMethodReflection = $classReflection->getNativeMethod($methodName);
|
||||||
if ($extendedMethodReflection->isStatic()) {
|
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
|
// could be static in doc type magic
|
||||||
|
|
|
@ -96,33 +96,33 @@ CODE_SAMPLE
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
$hasChanged = \false;
|
$hasChanged = \false;
|
||||||
$this->traverseNodesWithCallable($node, function (Node $node) use($classReflection, &$hasChanged) : ?StaticCall {
|
$this->traverseNodesWithCallable($node, function (Node $subNode) use($node, $classReflection, &$hasChanged) : ?StaticCall {
|
||||||
if (!$node instanceof MethodCall) {
|
if (!$subNode instanceof MethodCall) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (!$node->var instanceof Variable) {
|
if (!$subNode->var instanceof Variable) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (!$this->nodeNameResolver->isName($node->var, 'this')) {
|
if (!$this->nodeNameResolver->isName($subNode->var, 'this')) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (!$node->name instanceof Identifier) {
|
if (!$subNode->name instanceof Identifier) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
$methodName = $this->getName($node->name);
|
$methodName = $this->getName($subNode->name);
|
||||||
if ($methodName === null) {
|
if ($methodName === null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
$isStaticMethod = $this->staticAnalyzer->isStaticMethod($classReflection, $methodName);
|
$isStaticMethod = $this->staticAnalyzer->isStaticMethod($classReflection, $methodName, $node);
|
||||||
if (!$isStaticMethod) {
|
if (!$isStaticMethod) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if ($node->isFirstClassCallable()) {
|
if ($subNode->isFirstClassCallable()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
$hasChanged = \true;
|
$hasChanged = \true;
|
||||||
$objectReference = $this->resolveClassSelf($classReflection, $node);
|
$objectReference = $this->resolveClassSelf($classReflection, $subNode);
|
||||||
return $this->nodeFactory->createStaticCall($objectReference, $methodName, $node->args);
|
return $this->nodeFactory->createStaticCall($objectReference, $methodName, $subNode->args);
|
||||||
});
|
});
|
||||||
if ($hasChanged) {
|
if ($hasChanged) {
|
||||||
return $node;
|
return $node;
|
||||||
|
|
|
@ -19,12 +19,12 @@ final class VersionResolver
|
||||||
* @api
|
* @api
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
public const PACKAGE_VERSION = '29265cacf4b81261cb33885acaaa4edcb5885dd4';
|
public const PACKAGE_VERSION = '72cdbd0613318b797455deba64ebe6358d58af42';
|
||||||
/**
|
/**
|
||||||
* @api
|
* @api
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
public const RELEASE_DATE = '2023-10-25 15:01:10';
|
public const RELEASE_DATE = '2023-10-26 14:07:55';
|
||||||
/**
|
/**
|
||||||
* @var int
|
* @var int
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in New Issue
Block a user