mirror of
https://github.com/rectorphp/rector.git
synced 2025-03-13 20:12:07 +01:00
Updated Rector to commit 91df6147a4208433347ba68be65d9dcd7b756329
91df6147a4
[CodeQuality] Skip unused static methods in LocallyCalledStaticMethodToNonStaticRector, as should be handled by another rule (#6731)
This commit is contained in:
parent
d312db427a
commit
58e3b14615
@ -12,6 +12,7 @@ use PhpParser\Node\Expr\StaticCall;
|
||||
use PhpParser\Node\Expr\Variable;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use PhpParser\Node\Stmt\ClassMethod;
|
||||
use PhpParser\NodeFinder;
|
||||
use PhpParser\NodeVisitor;
|
||||
use PHPStan\Analyser\Scope;
|
||||
use PHPStan\Reflection\ClassReflection;
|
||||
@ -123,6 +124,9 @@ CODE_SAMPLE
|
||||
if ($this->isClassMethodCalledInAnotherStaticClassMethod($class, $classMethod)) {
|
||||
return null;
|
||||
}
|
||||
if ($this->isNeverCalled($class, $classMethod)) {
|
||||
return null;
|
||||
}
|
||||
// replace all the calls
|
||||
$classMethodName = $this->getName($classMethod);
|
||||
$className = $this->getName($class) ?? '';
|
||||
@ -177,7 +181,7 @@ CODE_SAMPLE
|
||||
$currentClassNamespacedName = (string) $this->getName($class);
|
||||
$currentClassMethodName = $this->getName($classMethod);
|
||||
$isInsideStaticClassMethod = \false;
|
||||
// check if called stati call somewhere in class, but only in static methods
|
||||
// check if called static call somewhere in class, but only in static methods
|
||||
foreach ($class->getMethods() as $checkedClassMethod) {
|
||||
// not a problem
|
||||
if (!$checkedClassMethod->isStatic()) {
|
||||
@ -209,4 +213,20 @@ CODE_SAMPLE
|
||||
}
|
||||
return \false;
|
||||
}
|
||||
/**
|
||||
* In case of never called method call,
|
||||
* it should be skipped and handled by another dead-code rule
|
||||
*/
|
||||
private function isNeverCalled(Class_ $class, ClassMethod $classMethod) : bool
|
||||
{
|
||||
$currentMethodName = $this->getName($classMethod);
|
||||
$nodeFinder = new NodeFinder();
|
||||
$methodCall = $nodeFinder->findFirst($class, function (Node $node) use($currentMethodName) : bool {
|
||||
if ($node instanceof MethodCall && $node->var instanceof Variable && $this->isName($node->var, 'this') && $this->isName($node->name, $currentMethodName)) {
|
||||
return \true;
|
||||
}
|
||||
return $node instanceof StaticCall && $this->isNames($node->class, ['self', 'static']) && $this->isName($node->name, $currentMethodName);
|
||||
});
|
||||
return !$methodCall instanceof Node;
|
||||
}
|
||||
}
|
||||
|
@ -19,12 +19,12 @@ final class VersionResolver
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '8efb34e74548d702dcc1fa15f9b6f22eaf2e08e3';
|
||||
public const PACKAGE_VERSION = '91df6147a4208433347ba68be65d9dcd7b756329';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2025-02-11 14:48:34';
|
||||
public const RELEASE_DATE = '2025-02-11 14:09:45';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user