Skip to content

Commit 220f33b

Browse files
authored
Covers scenario where func_get_args used in constructor (#7006)
1 parent fa08e0d commit 220f33b

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveUnusedConstructorParamRector\Fixture;
4+
5+
final class SkipUsedByGetFuncArgs
6+
{
7+
public $data;
8+
9+
public function __construct($hey, $man)
10+
{
11+
$this->data = func_get_args();
12+
}
13+
}

src/NodeAnalyzer/ParamAnalyzer.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ public function isParamUsedInClassMethod(ClassMethod $classMethod, Param $param)
5151
return NodeVisitor::STOP_TRAVERSAL;
5252
}
5353

54+
if ($this->isFuncGetArgsCall($node)) {
55+
$isParamUsed = true;
56+
}
57+
5458
if ($this->isUsedAsArg($node, $param)) {
5559
$isParamUsed = true;
5660
}
@@ -164,4 +168,17 @@ private function isParamUsed(Node $node, Param $param): bool
164168
$arguments = $this->funcCallManipulator->extractArgumentsFromCompactFuncCalls([$node]);
165169
return $this->nodeNameResolver->isNames($param, $arguments);
166170
}
171+
172+
private function isFuncGetArgsCall(Node $node): bool
173+
{
174+
if (! $node instanceof Node\Expr\FuncCall) {
175+
return false;
176+
}
177+
178+
if (! $this->nodeNameResolver->isName($node, 'func_get_args')) {
179+
return false;
180+
}
181+
182+
return true;
183+
}
167184
}

0 commit comments

Comments
 (0)