rector/rules/DeadCode/NodeCollector/UnusedParameterResolver.php
2024-11-20 15:58:53 +00:00

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;
}
}