[Php81] ArrayToFirstClassCallableRector should not skip non-public methods from owning scope #7760
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.
ArrayToFirstClassCallableRector currently skips over all callables that reference non-public methods, even if the callable is defined in the same scope as the method (e.g.
[$this, 'somePrivateMethod']).There are no existing test fixtures that demonstrate this behaviour either as an expected refactor or as an expected skip (the examples are all using public methods, or references from outside the owning scope).
It looks like this was the behaviour before #5929 was merged into v1.1.1. That was a bugfix for rectorphp/rector#8659 which was specific to cases where a private method is referenced from outside the owning scope.
I'm not sure if it was intentional to also stop refactoring callables that are defined and used within the same class? As far as I can tell, those should always be safe to convert to first-class callables.
I've added a test fixture to prove that these nodes are not currently refactored, and will push a second commit with a fix.
If you're not convinced about changing the default behaviour, then I could instead make this a configurable option for the rule?