Skip to content

Commit d3bbe6d

Browse files
committed
Updated Rector to commit c6d9903ba34109b976319601913dc08ffb5c8efd
rectorphp/rector-src@c6d9903 [DeadCode] Move Param used via variadic functions to ParamAnalyzer (#7016)
1 parent e26e06e commit d3bbe6d

8 files changed

Lines changed: 21 additions & 93 deletions

File tree

rules/DeadCode/NodeCollector/UnusedParameterResolver.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@ public function resolve(ClassMethod $classMethod) : array
2424
/** @var array<int, Param> $unusedParameters */
2525
$unusedParameters = [];
2626
foreach ($classMethod->params as $i => $param) {
27-
// skip property promotion
28-
/** @var Param $param */
29-
if ($param->isPromoted()) {
30-
continue;
31-
}
3227
if ($this->paramAnalyzer->isParamUsedInClassMethod($classMethod, $param)) {
3328
continue;
3429
}

rules/DeadCode/NodeManipulator/VariadicFunctionLikeDetector.php

Lines changed: 0 additions & 49 deletions
This file was deleted.

rules/DeadCode/Rector/ClassMethod/RemoveUnusedPrivateMethodParameterRector.php

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTagRemover;
1717
use Rector\Comments\NodeDocBlock\DocBlockUpdater;
1818
use Rector\DeadCode\NodeCollector\UnusedParameterResolver;
19-
use Rector\DeadCode\NodeManipulator\VariadicFunctionLikeDetector;
2019
use Rector\PhpParser\Node\BetterNodeFinder;
2120
use Rector\Rector\AbstractRector;
2221
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
@@ -26,10 +25,6 @@
2625
*/
2726
final class RemoveUnusedPrivateMethodParameterRector extends AbstractRector
2827
{
29-
/**
30-
* @readonly
31-
*/
32-
private VariadicFunctionLikeDetector $variadicFunctionLikeDetector;
3328
/**
3429
* @readonly
3530
*/
@@ -50,9 +45,8 @@ final class RemoveUnusedPrivateMethodParameterRector extends AbstractRector
5045
* @readonly
5146
*/
5247
private BetterNodeFinder $betterNodeFinder;
53-
public function __construct(VariadicFunctionLikeDetector $variadicFunctionLikeDetector, UnusedParameterResolver $unusedParameterResolver, PhpDocTagRemover $phpDocTagRemover, DocBlockUpdater $docBlockUpdater, PhpDocInfoFactory $phpDocInfoFactory, BetterNodeFinder $betterNodeFinder)
48+
public function __construct(UnusedParameterResolver $unusedParameterResolver, PhpDocTagRemover $phpDocTagRemover, DocBlockUpdater $docBlockUpdater, PhpDocInfoFactory $phpDocInfoFactory, BetterNodeFinder $betterNodeFinder)
5449
{
55-
$this->variadicFunctionLikeDetector = $variadicFunctionLikeDetector;
5650
$this->unusedParameterResolver = $unusedParameterResolver;
5751
$this->phpDocTagRemover = $phpDocTagRemover;
5852
$this->docBlockUpdater = $docBlockUpdater;
@@ -95,7 +89,7 @@ public function refactor(Node $node) : ?Node
9589
{
9690
$hasChanged = \false;
9791
foreach ($node->getMethods() as $classMethod) {
98-
if ($this->shouldSkipClassMethod($classMethod)) {
92+
if (!$classMethod->isPrivate()) {
9993
continue;
10094
}
10195
$unusedParameters = $this->unusedParameterResolver->resolve($classMethod);
@@ -195,16 +189,6 @@ private function resolveCallers(ClassMethod $classMethod, string $methodName, Ob
195189
return $this->isName($subNode->name, $methodName);
196190
});
197191
}
198-
private function shouldSkipClassMethod(ClassMethod $classMethod) : bool
199-
{
200-
if (!$classMethod->isPrivate()) {
201-
return \true;
202-
}
203-
if ($classMethod->params === []) {
204-
return \true;
205-
}
206-
return $this->variadicFunctionLikeDetector->isVariadic($classMethod);
207-
}
208192
/**
209193
* @param Param[] $unusedParameters
210194
*/

rules/DeadCode/Rector/ClassMethod/RemoveUnusedPublicMethodParameterRector.php

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use PhpParser\Node\Stmt\ClassMethod;
1010
use Rector\Configuration\Parameter\FeatureFlags;
1111
use Rector\DeadCode\NodeManipulator\ClassMethodParamRemover;
12-
use Rector\DeadCode\NodeManipulator\VariadicFunctionLikeDetector;
1312
use Rector\NodeAnalyzer\MagicClassMethodAnalyzer;
1413
use Rector\Php80\NodeAnalyzer\PhpAttributeAnalyzer;
1514
use Rector\Rector\AbstractRector;
@@ -20,10 +19,6 @@
2019
*/
2120
final class RemoveUnusedPublicMethodParameterRector extends AbstractRector
2221
{
23-
/**
24-
* @readonly
25-
*/
26-
private VariadicFunctionLikeDetector $variadicFunctionLikeDetector;
2722
/**
2823
* @readonly
2924
*/
@@ -36,9 +31,8 @@ final class RemoveUnusedPublicMethodParameterRector extends AbstractRector
3631
* @readonly
3732
*/
3833
private PhpAttributeAnalyzer $phpAttributeAnalyzer;
39-
public function __construct(VariadicFunctionLikeDetector $variadicFunctionLikeDetector, ClassMethodParamRemover $classMethodParamRemover, MagicClassMethodAnalyzer $magicClassMethodAnalyzer, PhpAttributeAnalyzer $phpAttributeAnalyzer)
34+
public function __construct(ClassMethodParamRemover $classMethodParamRemover, MagicClassMethodAnalyzer $magicClassMethodAnalyzer, PhpAttributeAnalyzer $phpAttributeAnalyzer)
4035
{
41-
$this->variadicFunctionLikeDetector = $variadicFunctionLikeDetector;
4236
$this->classMethodParamRemover = $classMethodParamRemover;
4337
$this->magicClassMethodAnalyzer = $magicClassMethodAnalyzer;
4438
$this->phpAttributeAnalyzer = $phpAttributeAnalyzer;
@@ -116,9 +110,6 @@ private function shouldSkipClassMethod(ClassMethod $classMethod, Class_ $class)
116110
if ($this->isName($classMethod->name, '__invoke') && $this->phpAttributeAnalyzer->hasPhpAttribute($class, 'Symfony\\Component\\Messenger\\Attribute\\AsMessageHandler')) {
117111
return \true;
118112
}
119-
if ($this->magicClassMethodAnalyzer->isUnsafeOverridden($classMethod)) {
120-
return \true;
121-
}
122-
return $this->variadicFunctionLikeDetector->isVariadic($classMethod);
113+
return $this->magicClassMethodAnalyzer->isUnsafeOverridden($classMethod);
123114
}
124115
}

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 = 'e6fb248f32da563c3046db1c6c81b52c4bfecda3';
22+
public const PACKAGE_VERSION = 'c6d9903ba34109b976319601913dc08ffb5c8efd';
2323
/**
2424
* @api
2525
* @var string
2626
*/
27-
public const RELEASE_DATE = '2025-06-22 14:51:03';
27+
public const RELEASE_DATE = '2025-06-22 21:18:26';
2828
/**
2929
* @var int
3030
*/

src/NodeAnalyzer/ParamAnalyzer.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ final class ParamAnalyzer
4444
* @readonly
4545
*/
4646
private BetterNodeFinder $betterNodeFinder;
47+
/**
48+
* @var string[]
49+
*/
50+
private const VARIADIC_FUNCTION_NAMES = ['func_get_arg', 'func_get_args', 'func_num_args'];
4751
public function __construct(NodeComparator $nodeComparator, NodeNameResolver $nodeNameResolver, FuncCallManipulator $funcCallManipulator, SimpleCallableNodeTraverser $simpleCallableNodeTraverser, BetterNodeFinder $betterNodeFinder)
4852
{
4953
$this->nodeComparator = $nodeComparator;
@@ -54,32 +58,37 @@ public function __construct(NodeComparator $nodeComparator, NodeNameResolver $no
5458
}
5559
public function isParamUsedInClassMethod(ClassMethod $classMethod, Param $param) : bool
5660
{
61+
if ($param->isPromoted()) {
62+
return \true;
63+
}
5764
$isParamUsed = \false;
5865
if ($param->var instanceof Error) {
5966
return \false;
6067
}
6168
$this->simpleCallableNodeTraverser->traverseNodesWithCallable($classMethod->stmts, function (Node $node) use(&$isParamUsed, $param) : ?int {
62-
if ($isParamUsed) {
63-
return NodeVisitor::STOP_TRAVERSAL;
64-
}
65-
if ($this->isFuncGetArgsCall($node)) {
69+
if ($this->isVariadicFuncCall($node)) {
6670
$isParamUsed = \true;
71+
return NodeVisitor::STOP_TRAVERSAL;
6772
}
6873
if ($this->isUsedAsArg($node, $param)) {
6974
$isParamUsed = \true;
75+
return NodeVisitor::STOP_TRAVERSAL;
7076
}
7177
// skip nested anonymous class
7278
if ($node instanceof Class_ || $node instanceof Function_) {
7379
return NodeVisitor::DONT_TRAVERSE_CURRENT_AND_CHILDREN;
7480
}
7581
if ($node instanceof Variable && $this->nodeComparator->areNodesEqual($node, $param->var)) {
7682
$isParamUsed = \true;
83+
return NodeVisitor::STOP_TRAVERSAL;
7784
}
7885
if ($node instanceof Closure && $this->isVariableInClosureUses($node, $param->var)) {
7986
$isParamUsed = \true;
87+
return NodeVisitor::STOP_TRAVERSAL;
8088
}
8189
if ($this->isParamUsed($node, $param)) {
8290
$isParamUsed = \true;
91+
return NodeVisitor::STOP_TRAVERSAL;
8392
}
8493
return null;
8594
});
@@ -154,11 +163,11 @@ private function isParamUsed(Node $node, Param $param) : bool
154163
$arguments = $this->funcCallManipulator->extractArgumentsFromCompactFuncCalls([$node]);
155164
return $this->nodeNameResolver->isNames($param, $arguments);
156165
}
157-
private function isFuncGetArgsCall(Node $node) : bool
166+
private function isVariadicFuncCall(Node $node) : bool
158167
{
159168
if (!$node instanceof FuncCall) {
160169
return \false;
161170
}
162-
return $this->nodeNameResolver->isName($node, 'func_get_args');
171+
return $this->nodeNameResolver->isNames($node, self::VARIADIC_FUNCTION_NAMES);
163172
}
164173
}

vendor/composer/autoload_classmap.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1302,7 +1302,6 @@
13021302
'Rector\\DeadCode\\NodeManipulator\\ControllerClassMethodManipulator' => $baseDir . '/rules/DeadCode/NodeManipulator/ControllerClassMethodManipulator.php',
13031303
'Rector\\DeadCode\\NodeManipulator\\CountManipulator' => $baseDir . '/rules/DeadCode/NodeManipulator/CountManipulator.php',
13041304
'Rector\\DeadCode\\NodeManipulator\\LivingCodeManipulator' => $baseDir . '/rules/DeadCode/NodeManipulator/LivingCodeManipulator.php',
1305-
'Rector\\DeadCode\\NodeManipulator\\VariadicFunctionLikeDetector' => $baseDir . '/rules/DeadCode/NodeManipulator/VariadicFunctionLikeDetector.php',
13061305
'Rector\\DeadCode\\PhpDoc\\DeadParamTagValueNodeAnalyzer' => $baseDir . '/rules/DeadCode/PhpDoc/DeadParamTagValueNodeAnalyzer.php',
13071306
'Rector\\DeadCode\\PhpDoc\\DeadReturnTagValueNodeAnalyzer' => $baseDir . '/rules/DeadCode/PhpDoc/DeadReturnTagValueNodeAnalyzer.php',
13081307
'Rector\\DeadCode\\PhpDoc\\DeadVarTagValueNodeAnalyzer' => $baseDir . '/rules/DeadCode/PhpDoc/DeadVarTagValueNodeAnalyzer.php',

vendor/composer/autoload_static.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1521,7 +1521,6 @@ class ComposerStaticInit78fb90a05527c4e1e3e0271783524c1e
15211521
'Rector\\DeadCode\\NodeManipulator\\ControllerClassMethodManipulator' => __DIR__ . '/../..' . '/rules/DeadCode/NodeManipulator/ControllerClassMethodManipulator.php',
15221522
'Rector\\DeadCode\\NodeManipulator\\CountManipulator' => __DIR__ . '/../..' . '/rules/DeadCode/NodeManipulator/CountManipulator.php',
15231523
'Rector\\DeadCode\\NodeManipulator\\LivingCodeManipulator' => __DIR__ . '/../..' . '/rules/DeadCode/NodeManipulator/LivingCodeManipulator.php',
1524-
'Rector\\DeadCode\\NodeManipulator\\VariadicFunctionLikeDetector' => __DIR__ . '/../..' . '/rules/DeadCode/NodeManipulator/VariadicFunctionLikeDetector.php',
15251524
'Rector\\DeadCode\\PhpDoc\\DeadParamTagValueNodeAnalyzer' => __DIR__ . '/../..' . '/rules/DeadCode/PhpDoc/DeadParamTagValueNodeAnalyzer.php',
15261525
'Rector\\DeadCode\\PhpDoc\\DeadReturnTagValueNodeAnalyzer' => __DIR__ . '/../..' . '/rules/DeadCode/PhpDoc/DeadReturnTagValueNodeAnalyzer.php',
15271526
'Rector\\DeadCode\\PhpDoc\\DeadVarTagValueNodeAnalyzer' => __DIR__ . '/../..' . '/rules/DeadCode/PhpDoc/DeadVarTagValueNodeAnalyzer.php',

0 commit comments

Comments
 (0)