Description:
Hi Rector team! 👋
I'm encountering a limitation with the ClosureToArrowFunctionRector rule when working with closures that use use($variable) in Laravel projects.
Example:
$conta = array_filter($informativoPorAno,
function (array $i) use ($request): bool {
return $i['associado']['conta_nao_formatada'] == $request->conta;
}
);
Rector transforms this into:
$conta = array_filter($informativoPorAno,
fn(array $i): bool => $i['associado']['conta_nao_formatada'] == $request->conta
);
This causes a runtime error because fn() does not support use($request) unless the variable is directly referenced in the expression. In Laravel, this pattern is common when using closures inside controller methods, and the $request object is often passed via use().
To prevent this, I had to disable the rule for the entire file in rector.php:
ClosureToArrowFunctionRector::class => [
__DIR__ . '/app/Http/Controllers/ColaboradorController.php'
]
While this works, it prevents me from applying the rule consistently across the rest of the file.
It would be extremely helpful to support skipping specific lines or blocks
This would allow me to:
- Keep a consistent rector.php config across all my projects
- Apply the rule globally while skipping only the problematic closures
- Avoid disabling the rule for entire files unnecessarily
Description:
Hi Rector team! 👋
I'm encountering a limitation with the ClosureToArrowFunctionRector rule when working with closures that use use($variable) in Laravel projects.
Example:
Rector transforms this into:
This causes a runtime error because fn() does not support use($request) unless the variable is directly referenced in the expression. In Laravel, this pattern is common when using closures inside controller methods, and the $request object is often passed via use().
To prevent this, I had to disable the rule for the entire file in rector.php:
While this works, it prevents me from applying the rule consistently across the rest of the file.
It would be extremely helpful to support skipping specific lines or blocks
This would allow me to: