Functions/RestrictedFunctions::is_targetted_token(): improve the method #863
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.
The
RestrictedFunctions::is_targetted_token()method was basically a duplicate of the upstream/parent method with some additional code to handle one specific situation (method calls on a specific variable).However, the parent method has been updated significantly since the code was copied and this sniff wasn't benefitting from that.
This commit rewrites the
RestrictedFunctions::is_targetted_token()method to defer to the parent method in all cases, except for the one specific situation we want to account for.Additionally, it stabilizes and improves the token walking done for that specific situation, as well as takes the PHP 8.0+ nullsafe object operator into account.
Includes a number of tests, some to cover the improvements inherited from the parent method, some to cover the improved code in the overloaded method.
Includes documenting how PHP 8.1+ first class callables are handled by the sniff.
Closes #518