Skip to content

Commit 41c2989

Browse files
committed
skip bare spread arg as well
1 parent b147022 commit 41c2989

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ParamTypeByParentCallTypeRector\Fixture;
4+
5+
use Rector\Tests\TypeDeclaration\Rector\ClassMethod\ParamTypeByParentCallTypeRector\Source\ParentClassWithArraySpread;
6+
7+
final class SkipJustSPreadedArg extends ParentClassWithArraySpread
8+
{
9+
public function __construct($items)
10+
{
11+
parent::__construct(...$items);
12+
}
13+
}

rules/TypeDeclaration/Rector/ClassMethod/ParamTypeByParentCallTypeRector.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
namespace Rector\TypeDeclaration\Rector\ClassMethod;
66

77
use PhpParser\Node;
8+
use PhpParser\Node\Arg;
89
use PhpParser\Node\Expr\StaticCall;
10+
use PhpParser\Node\Expr\Variable;
911
use PhpParser\Node\Param;
1012
use PhpParser\Node\Stmt\ClassMethod;
1113
use PHPStan\Reflection\ClassReflection;
@@ -108,6 +110,10 @@ public function refactor(Node $node): ?Node
108110
continue;
109111
}
110112

113+
if ($this->isParamUsedInSpreadArg($node, $param)) {
114+
continue;
115+
}
116+
111117
$parentParam = $this->callerParamMatcher->matchParentParam($parentStaticCall, $param, $scope);
112118
if (! $parentParam instanceof Param) {
113119
continue;
@@ -172,4 +178,23 @@ private function shouldSkip(ClassMethod $classMethod): bool
172178

173179
return ! $classReflection->isClass();
174180
}
181+
182+
private function isParamUsedInSpreadArg(ClassMethod $classMethod, Param $param): bool
183+
{
184+
/** @var Arg[] $args */
185+
$args = $this->betterNodeFinder->findInstancesOfScoped((array) $classMethod->stmts, Arg::class);
186+
187+
$paramName = $this->getName($param);
188+
foreach ($args as $arg) {
189+
if (! $arg->unpack) {
190+
continue;
191+
}
192+
193+
if ($arg->value instanceof Variable && $this->isName($arg->value, $paramName)) {
194+
return true;
195+
}
196+
}
197+
198+
return false;
199+
}
175200
}

0 commit comments

Comments
 (0)