2019-11-05 16:33:38 +01:00
|
|
|
<?php
|
|
|
|
|
2021-05-09 20:15:43 +00:00
|
|
|
declare (strict_types=1);
|
2022-06-06 17:12:56 +00:00
|
|
|
namespace Rector\Removing\NodeManipulator;
|
2019-11-05 16:33:38 +01:00
|
|
|
|
2022-06-06 17:12:56 +00:00
|
|
|
use PhpParser\Node\Stmt\ClassMethod;
|
2021-02-08 22:00:45 +01:00
|
|
|
final class ComplexNodeRemover
|
2019-11-05 16:33:38 +01:00
|
|
|
{
|
2023-05-29 14:21:32 +00:00
|
|
|
/**
|
|
|
|
* @param int[] $paramKeysToBeRemoved
|
|
|
|
* @return int[]
|
|
|
|
*/
|
|
|
|
public function processRemoveParamWithKeys(ClassMethod $classMethod, array $paramKeysToBeRemoved) : array
|
|
|
|
{
|
|
|
|
$totalKeys = \count($classMethod->params) - 1;
|
|
|
|
$removedParamKeys = [];
|
|
|
|
foreach ($paramKeysToBeRemoved as $paramKeyToBeRemoved) {
|
|
|
|
$startNextKey = $paramKeyToBeRemoved + 1;
|
|
|
|
for ($nextKey = $startNextKey; $nextKey <= $totalKeys; ++$nextKey) {
|
|
|
|
if (!isset($classMethod->params[$nextKey])) {
|
|
|
|
// no next param, break the inner loop, remove the param
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (\in_array($nextKey, $paramKeysToBeRemoved, \true)) {
|
|
|
|
// keep searching next key not in $paramKeysToBeRemoved
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
unset($classMethod->params[$paramKeyToBeRemoved]);
|
|
|
|
$removedParamKeys[] = $paramKeyToBeRemoved;
|
|
|
|
}
|
|
|
|
return $removedParamKeys;
|
|
|
|
}
|
2019-11-05 16:33:38 +01:00
|
|
|
}
|