feat(code-action): convert arrow function to closure - #191
Merged
Conversation
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Add a refactor.rewrite code action that converts arrow functions to
anonymous closures: `fn($x) => $x * 2` becomes
`function($x) { return $x * 2; }`.
Variables from the outer scope used in the expression are automatically
detected and captured via a `use()` clause. `$this` is excluded since
closures bind it automatically (unless static). Nested arrow functions
are handled by extending the parameter exclusion set.
Preserves:
- static keyword
- Return type hints
- Parameter type hints
Includes 10 unit tests covering: simple expressions, type hints,
static arrows, single/multiple variable capture, $this exclusion,
parameter exclusion, method calls with captures, and deduplication.
Closes PHPantom-dev#148
Signed-off-by: Anders Jenbo <anders@jenbo.dk>
AJenbo
force-pushed
the
calebdw/push-tlprmqnqspkt
branch
from
July 4, 2026 02:38
5368dff to
762be3a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add a refactor.rewrite code action that converts arrow functions to anonymous closures:
fn($x) => $x * 2becomesfunction($x) { return $x * 2; }.Variables from the outer scope used in the expression are automatically detected and captured via a
use()clause.$thisis excluded since closures bind it automatically (unless static). Nested arrow functions are handled by extending the parameter exclusion set.Preserves:
Includes 10 unit tests covering: simple expressions, type hints, static arrows, single/multiple variable capture, $this exclusion, parameter exclusion, method calls with captures, and deduplication.
Closes #148