Skip to content

Commit

Permalink
[DeadCode] Clean up PHPStan notice on ComplexNodeRemover::processRemo…
Browse files Browse the repository at this point in the history
…veParamWithKeys() (#4018)
  • Loading branch information
samsonasik committed May 29, 2023
1 parent e604829 commit 4ea7d0f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
4 changes: 0 additions & 4 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,3 @@ parameters:
-
message: '#Offset 0 does not exist on array<PhpParser\\Node\\Stmt>\|null#'
path: rules/CodingStyle/Rector/ClassMethod/ReturnArrayClassMethodToYieldRector.php

-
message: '#Method "processRemoveParamWithKeys\(\)" returns bool type, so the name should start with is/has/was#'
path: rules/Removing/NodeManipulator/ComplexNodeRemover.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ private function processRemoveParams(ClassMethod $classMethod): ?ClassMethod
return null;
}

$hasRemoved = $this->complexNodeRemover
$removedParamKeys = $this->complexNodeRemover
->processRemoveParamWithKeys($classMethod, $paramKeysToBeRemoved);

if ($hasRemoved) {
if ($removedParamKeys !== []) {
return $classMethod;
}

Expand Down
14 changes: 7 additions & 7 deletions rules/Removing/NodeManipulator/ComplexNodeRemover.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,34 +171,34 @@ private function removeConstructorDependency(Class_ $class, string $propertyName

/**
* @param int[] $paramKeysToBeRemoved
* @return int[]
*/
public function processRemoveParamWithKeys(ClassMethod $classMethod, array $paramKeysToBeRemoved): bool
public function processRemoveParamWithKeys(ClassMethod $classMethod, array $paramKeysToBeRemoved): array
{
$totalKeys = count($classMethod->params) - 1;
$hasRemoved = false;
$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
unset($classMethod->params[$paramKeyToBeRemoved]);
return true;
break;
}

if (in_array($nextKey, $paramKeysToBeRemoved, true)) {
// keep searching next key not in $paramKeysToBeRemoved
continue;
}

return $hasRemoved;
return [];
}

unset($classMethod->params[$paramKeyToBeRemoved]);
$hasRemoved = true;
$removedParamKeys[] = $paramKeyToBeRemoved;
}

return $hasRemoved;
return $removedParamKeys;
}

/**
Expand Down

0 comments on commit 4ea7d0f

Please sign in to comment.