Skip to content

Commit 69fea4f

Browse files
committed
Updated Rector to commit ced707e53e62a8a466508909e889990e52178c94
rectorphp/rector-src@ced707e [DeadCode] Use IsClassMethodUsedAnalyzer service on RemoveEmptyClassMethodRector (#6909)
1 parent 942c4dc commit 69fea4f

2 files changed

Lines changed: 9 additions & 43 deletions

File tree

rules/DeadCode/Rector/ClassMethod/RemoveEmptyClassMethodRector.php

Lines changed: 7 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,16 @@
44
namespace Rector\DeadCode\Rector\ClassMethod;
55

66
use PhpParser\Node;
7-
use PhpParser\Node\Expr\Array_;
8-
use PhpParser\Node\Expr\MethodCall;
9-
use PhpParser\Node\Expr\Variable;
107
use PhpParser\Node\Name\FullyQualified;
118
use PhpParser\Node\Stmt\Class_;
129
use PhpParser\Node\Stmt\ClassMethod;
1310
use PHPStan\PhpDocParser\Ast\PhpDoc\DeprecatedTagValueNode;
1411
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
1512
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
13+
use Rector\DeadCode\NodeAnalyzer\IsClassMethodUsedAnalyzer;
1614
use Rector\DeadCode\NodeManipulator\ControllerClassMethodManipulator;
1715
use Rector\NodeAnalyzer\ParamAnalyzer;
18-
use Rector\NodeCollector\NodeAnalyzer\ArrayCallableMethodMatcher;
1916
use Rector\NodeManipulator\ClassMethodManipulator;
20-
use Rector\PhpParser\Node\BetterNodeFinder;
2117
use Rector\PHPStan\ScopeFetcher;
2218
use Rector\Rector\AbstractRector;
2319
use Rector\ValueObject\MethodName;
@@ -47,19 +43,14 @@ final class RemoveEmptyClassMethodRector extends AbstractRector
4743
/**
4844
* @readonly
4945
*/
50-
private BetterNodeFinder $betterNodeFinder;
51-
/**
52-
* @readonly
53-
*/
54-
private ArrayCallableMethodMatcher $arrayCallableMethodMatcher;
55-
public function __construct(ClassMethodManipulator $classMethodManipulator, ControllerClassMethodManipulator $controllerClassMethodManipulator, ParamAnalyzer $paramAnalyzer, PhpDocInfoFactory $phpDocInfoFactory, BetterNodeFinder $betterNodeFinder, ArrayCallableMethodMatcher $arrayCallableMethodMatcher)
46+
private IsClassMethodUsedAnalyzer $isClassMethodUsedAnalyzer;
47+
public function __construct(ClassMethodManipulator $classMethodManipulator, ControllerClassMethodManipulator $controllerClassMethodManipulator, ParamAnalyzer $paramAnalyzer, PhpDocInfoFactory $phpDocInfoFactory, IsClassMethodUsedAnalyzer $isClassMethodUsedAnalyzer)
5648
{
5749
$this->classMethodManipulator = $classMethodManipulator;
5850
$this->controllerClassMethodManipulator = $controllerClassMethodManipulator;
5951
$this->paramAnalyzer = $paramAnalyzer;
6052
$this->phpDocInfoFactory = $phpDocInfoFactory;
61-
$this->betterNodeFinder = $betterNodeFinder;
62-
$this->arrayCallableMethodMatcher = $arrayCallableMethodMatcher;
53+
$this->isClassMethodUsedAnalyzer = $isClassMethodUsedAnalyzer;
6354
}
6455
public function getRuleDefinition() : RuleDefinition
6556
{
@@ -133,16 +124,10 @@ private function shouldSkipNonFinalNonPrivateClassMethod(Class_ $class, ClassMet
133124
}
134125
private function shouldSkipClassMethod(Class_ $class, ClassMethod $classMethod) : bool
135126
{
136-
$desiredClassMethodName = $this->getName($classMethod);
137-
$className = (string) $this->getName($class);
138127
// is method called somewhere else in the class?
139-
foreach ($class->getMethods() as $anotherClassMethod) {
140-
if ($anotherClassMethod === $classMethod) {
141-
continue;
142-
}
143-
if ($this->containsMethodCallOrArrayCallable($anotherClassMethod, $desiredClassMethodName, $className)) {
144-
return \true;
145-
}
128+
$scope = ScopeFetcher::fetch($classMethod);
129+
if ($this->isClassMethodUsedAnalyzer->isClassMethodUsed($class, $classMethod, $scope)) {
130+
return \true;
146131
}
147132
if ($this->classMethodManipulator->isNamedConstructor($classMethod)) {
148133
return \true;
@@ -173,23 +158,4 @@ private function hasDeprecatedAnnotation(ClassMethod $classMethod) : bool
173158
}
174159
return $phpDocInfo->hasByType(DeprecatedTagValueNode::class);
175160
}
176-
private function containsMethodCallOrArrayCallable(ClassMethod $anotherClassMethod, string $desiredClassMethodName, string $className) : bool
177-
{
178-
$scope = ScopeFetcher::fetch($anotherClassMethod);
179-
return (bool) $this->betterNodeFinder->findFirst($anotherClassMethod, function (Node $node) use($desiredClassMethodName, $className, $scope) : bool {
180-
if ($node instanceof Array_) {
181-
return (bool) $this->arrayCallableMethodMatcher->match($node, $scope, $className);
182-
}
183-
if (!$node instanceof MethodCall) {
184-
return \false;
185-
}
186-
if (!$node->var instanceof Variable) {
187-
return \false;
188-
}
189-
if (!$this->isName($node->var, 'this')) {
190-
return \false;
191-
}
192-
return $this->isName($node->name, $desiredClassMethodName);
193-
});
194-
}
195161
}

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 = 'b68824a85e025a6e6806f605eb59874d412cc1b1';
22+
public const PACKAGE_VERSION = 'ced707e53e62a8a466508909e889990e52178c94';
2323
/**
2424
* @api
2525
* @var string
2626
*/
27-
public const RELEASE_DATE = '2025-05-19 21:16:40';
27+
public const RELEASE_DATE = '2025-05-20 05:01:26';
2828
/**
2929
* @var int
3030
*/

0 commit comments

Comments
 (0)