Generic/FunctionCallArgumentSpacing: bug fix - ignore commas in nested match structures + minor efficiency tweak #513
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.
Description
Follow up on #497, see #497 (review)
Generic/FunctionCallArgumentSpacing: efficiency fix - skip over arrow functions
PHP 7.4 introduced arrow functions.
While arrow functions being passed as an argument in a function call will not lead to false positives for this sniff - at least, I haven't been able to come up with a code sample in which it would 1 -, skipping over them is still beneficial as it prevents unnecessary token walking.
Mind: the
scope_closer
of the arrow function may be the comma separating the arrow function argument from the next function call argument, so we need to step one token back to prevent false negatives on those comma's.Either way, this is now handled.
Includes unit tests.
Generic/FunctionCallArgumentSpacing: bug fix - ignore commas in nested match structures
PHP 8.0 introduced match control structures, which can be passed in a function call (though probably/hopefully this is not very common as it makes for harder to read code).
The comma's within match control structures should be checked by a sniff which handled that control structure and should not be treated as comma's belonging to the function call.
As things are, this is currently not the case, which leads to false positives.
Fixed now.
Includes test.
Suggested changelog entry
Related issues/external references
Related to #497
Types of changes
Footnotes
comma's in arrow functions will always be nested within parentheses, within a short array or within a nested closure or anonymous class, all of which the sniff already ignores. ↩