mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-20 08:05:29 +01:00
45 lines
1.3 KiB
PHP
45 lines
1.3 KiB
PHP
<?php
|
|
|
|
declare (strict_types=1);
|
|
namespace Rector\DeadCode\NodeManipulator;
|
|
|
|
use PhpParser\Node\Stmt\ClassMethod;
|
|
use Rector\NodeAnalyzer\ParamAnalyzer;
|
|
use Rector\Removing\NodeManipulator\ComplexNodeRemover;
|
|
final class ClassMethodParamRemover
|
|
{
|
|
/**
|
|
* @readonly
|
|
* @var \Rector\NodeAnalyzer\ParamAnalyzer
|
|
*/
|
|
private $paramAnalyzer;
|
|
/**
|
|
* @readonly
|
|
* @var \Rector\Removing\NodeManipulator\ComplexNodeRemover
|
|
*/
|
|
private $complexNodeRemover;
|
|
public function __construct(ParamAnalyzer $paramAnalyzer, ComplexNodeRemover $complexNodeRemover)
|
|
{
|
|
$this->paramAnalyzer = $paramAnalyzer;
|
|
$this->complexNodeRemover = $complexNodeRemover;
|
|
}
|
|
public function processRemoveParams(ClassMethod $classMethod) : ?ClassMethod
|
|
{
|
|
$paramKeysToBeRemoved = [];
|
|
foreach ($classMethod->params as $key => $param) {
|
|
if ($this->paramAnalyzer->isParamUsedInClassMethod($classMethod, $param)) {
|
|
continue;
|
|
}
|
|
$paramKeysToBeRemoved[] = $key;
|
|
}
|
|
if ($paramKeysToBeRemoved === []) {
|
|
return null;
|
|
}
|
|
$removedParamKeys = $this->complexNodeRemover->processRemoveParamWithKeys($classMethod, $paramKeysToBeRemoved);
|
|
if ($removedParamKeys !== []) {
|
|
return $classMethod;
|
|
}
|
|
return null;
|
|
}
|
|
}
|