Skip to content

Commit

Permalink
[BUGFIX] Use arg as var name instead of fixed one
Browse files Browse the repository at this point in the history
Resolves: #3940
  • Loading branch information
helsner committed Dec 22, 2023
1 parent 9b3fdfe commit 3d7c016
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ public function refactor(Node $node): ?Node
$explodeFuncCall = $this->nodeFactory->createFuncCall('explode', [',', $node->args[1]]);

$itemVariable = new Variable('item');
$elementVariable = new Variable($this->nodeNameResolver->getName($node->args[0]->value));

Check failure on line 62 in src/Rector/v11/v3/SubstituteMethodRmFromListOfGeneralUtilityRector.php

View workflow job for this annotation

GitHub Actions / 7.4 PHPStan

Parameter #1 $name of class PhpParser\Node\Expr\Variable constructor expects PhpParser\Node\Expr|string, string|null given.

Check failure on line 62 in src/Rector/v11/v3/SubstituteMethodRmFromListOfGeneralUtilityRector.php

View workflow job for this annotation

GitHub Actions / 8 PHPStan

Parameter #1 $name of class PhpParser\Node\Expr\Variable constructor expects PhpParser\Node\Expr|string, string|null given.

Check failure on line 62 in src/Rector/v11/v3/SubstituteMethodRmFromListOfGeneralUtilityRector.php

View workflow job for this annotation

GitHub Actions / 8.1 PHPStan

Parameter #1 $name of class PhpParser\Node\Expr\Variable constructor expects PhpParser\Node\Expr|string, string|null given.

$stmts = [new Return_(new Equal(new Variable('element'), $itemVariable))];
$stmts = [new Return_(new Equal($elementVariable, $itemVariable))];

$closureFunction = $this->anonymousFunctionFactory->create([new Param($itemVariable)], $stmts, null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ $list = '1,2,3';

$newList = GeneralUtility::rmFromList($element, $list);

$newElementVarName = '1';
$newListVarName = '1,2,3';

$newListTwo = GeneralUtility::rmFromList($newElementVarName, $newListVarName);

?>
-----
<?php
Expand All @@ -24,4 +29,11 @@ $newList = implode(',', array_filter(explode(',', $list), function ($item) use (
return $element == $item;
}));

$newElementVarName = '1';
$newListVarName = '1,2,3';

$newListTwo = implode(',', array_filter(explode(',', $newListVarName), function ($item) use ($newElementVarName) {
return $newElementVarName == $item;
}));

?>

0 comments on commit 3d7c016

Please sign in to comment.