mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-17 13:28:18 +01:00
9a4a5b2bc5
eb5df4dde7
Use vendor-patches main branch (#6453)
40 lines
1.0 KiB
PHP
40 lines
1.0 KiB
PHP
<?php
|
|
|
|
declare (strict_types=1);
|
|
namespace Rector\DeadCode\NodeCollector;
|
|
|
|
use PhpParser\Node\Param;
|
|
use PhpParser\Node\Stmt\ClassMethod;
|
|
use Rector\NodeAnalyzer\ParamAnalyzer;
|
|
final class UnusedParameterResolver
|
|
{
|
|
/**
|
|
* @readonly
|
|
*/
|
|
private ParamAnalyzer $paramAnalyzer;
|
|
public function __construct(ParamAnalyzer $paramAnalyzer)
|
|
{
|
|
$this->paramAnalyzer = $paramAnalyzer;
|
|
}
|
|
/**
|
|
* @return array<int, Param>
|
|
*/
|
|
public function resolve(ClassMethod $classMethod) : array
|
|
{
|
|
/** @var array<int, Param> $unusedParameters */
|
|
$unusedParameters = [];
|
|
foreach ($classMethod->params as $i => $param) {
|
|
// skip property promotion
|
|
/** @var Param $param */
|
|
if ($param->flags !== 0) {
|
|
continue;
|
|
}
|
|
if ($this->paramAnalyzer->isParamUsedInClassMethod($classMethod, $param)) {
|
|
continue;
|
|
}
|
|
$unusedParameters[$i] = $param;
|
|
}
|
|
return $unusedParameters;
|
|
}
|
|
}
|