-
-
Notifications
You must be signed in to change notification settings - Fork 424
Static closure rule ignores arguments with $this binding #7721
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
peterfox
wants to merge
14
commits into
rectorphp:main
Choose a base branch
from
peterfox:feature/static-closure-improved
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Static closure rule ignores arguments with $this binding #7721
peterfox
wants to merge
14
commits into
rectorphp:main
from
peterfox:feature/static-closure-improved
Conversation
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
samsonasik
reviewed
Dec 6, 2025
src/NodeAnalyzer/CallLikeExpectsThisBindedClosureArgsAnalyzer.php
Outdated
Show resolved
Hide resolved
samsonasik
approved these changes
Dec 6, 2025
Member
samsonasik
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me 👍
TomasVotruba
reviewed
Dec 6, 2025
rules-tests/CodingStyle/Rector/Closure/StaticClosureRector/Source/functions.php
Show resolved
Hide resolved
TomasVotruba
reviewed
Dec 6, 2025
1310b07 to
91e3be0
Compare
samsonasik
reviewed
Dec 7, 2025
src/NodeAnalyzer/CallLikeExpectsThisBindedClosureArgsAnalyzer.php
Outdated
Show resolved
Hide resolved
samsonasik
approved these changes
Dec 7, 2025
samsonasik
reviewed
Dec 8, 2025
src/NodeAnalyzer/CallLikeExpectsThisBoundClosureArgsAnalyzer.php
Outdated
Show resolved
Hide resolved
…e-improved # Conflicts: # src/DependencyInjection/LazyContainerFactory.php # src/NodeTypeResolver/Node/AttributeKey.php # src/PhpParser/NodeVisitor/CallLikeThisBoundClosureArgsNodeVisitor.php
…e-improved # Conflicts: # rules/CodingStyle/Guard/ArrowFunctionAndClosureFirstClassCallableGuard.php
samsonasik
reviewed
Dec 14, 2025
src/NodeAnalyzer/CallLikeExpectsThisBoundClosureArgsAnalyzer.php
Outdated
Show resolved
Hide resolved
samsonasik
reviewed
Dec 14, 2025
Member
|
@peterfox unit test somehow error |
samsonasik
approved these changes
Dec 24, 2025
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.
Changes
CallLikeExpectsThisBindedClosureArgsAnalyzerwhich allows the detection of the@param-closure-this.@param-closure-thisand then skip these closuresWhy
Often there's a few scenarios where the static closure rule causes problems and starts to add the keyword where it will break code because it's being used as a argument for a parameter which will be later bound to an object. This can't be done if the closure is static and causes a runtime error.
This happens quite a lot in Laravel projects. Example issues driftingly/rector-laravel#102
Notes
I had to use
method.notFoundto silence PHPStan. I don't know why this is the case as the code works but something is up with PHPStan.I also created a new analyser to make this work but I'm happy to take this method and put it into a pre-existing one if adding a new one seems pointless.