rector/rules/DeadCode/NodeCollector/UnusedParameterResolver.php
Tomas Votruba aa2cb1b997 Updated Rector to commit 0eba231b075849ea4b327ce96c28ec359e7b7636
0eba231b07 [PHP 8.1] Move ConstantListClassToEnumRector to PHP 8.1 (#2444)
2022-06-06 17:12:56 +00:00

41 lines
1.1 KiB
PHP

<?php
declare (strict_types=1);
namespace Rector\DeadCode\NodeCollector;
use PhpParser\Node\Param;
use PhpParser\Node\Stmt\ClassMethod;
use Rector\Core\NodeAnalyzer\ParamAnalyzer;
final class UnusedParameterResolver
{
/**
* @readonly
* @var \Rector\Core\NodeAnalyzer\ParamAnalyzer
*/
private $paramAnalyzer;
public function __construct(\Rector\Core\NodeAnalyzer\ParamAnalyzer $paramAnalyzer)
{
$this->paramAnalyzer = $paramAnalyzer;
}
/**
* @return Param[]
*/
public function resolve(\PhpParser\Node\Stmt\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;
}
}