Skip to content

Commit

Permalink
TASK: Do not touch return inside a closure (#3213)
Browse files Browse the repository at this point in the history
Resolves: #3084
  • Loading branch information
sabbelasichon authored Nov 13, 2022
1 parent 66f580b commit 6ab3d15
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Ssch\TYPO3Rector\Rector\v11\v0;

use PhpParser\Node;
use PhpParser\Node\Expr\Closure;
use PhpParser\Node\Expr\Exit_;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\MethodCall;
Expand Down Expand Up @@ -54,6 +55,13 @@ public function refactor(Node $node): ?Node

$returns = $this->findReturns($node);
foreach ($returns as $return) {
// If it is inside a closure do nothing
$closure = $this->betterNodeFinder->findParentType($return, Closure::class);

if (null !== $closure) {
continue;
}

$returnCallExpression = $return->expr;

if ($returnCallExpression instanceof FuncCall && $this->isName(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ class MyRefactoredController extends ActionController
return new ForwardResponse('another');
}

public function somethingAction($range): ResponseInterface
{
$years = array_map(static function ($item): string {
return 'C'.$item.'-';
}, $range);

return $this->htmlResponse($years);
}

abstract public function listAction($filter = null, string $letter = ''): ResponseInterface;
}

Expand Down

0 comments on commit 6ab3d15

Please sign in to comment.