mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-17 21:38:22 +01:00
aa2cb1b997
0eba231b07
[PHP 8.1] Move ConstantListClassToEnumRector to PHP 8.1 (#2444)
41 lines
1.1 KiB
PHP
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;
|
|
}
|
|
}
|