Skip to content
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

Squiz/MultiLineFunctionDeclaration: bug fix - skip over attributes #609

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Sep 8, 2024

Description

The sniff looks for T_COMMA tokens to find the start of the next parameter and skips over parenthesis sets and square brackets sets (like short arrays) to prevent mismatching on a T_COMMA which is not a parameter separator.

This logic did not take parameter attributes into account, which can contain multiple comma-separated attributes, so should also be skipped over.

Fixed now. Includes plenty of tests.

Also includes minor stability fix for the parentheses/square brackets skipping.

Notes:

  • It could be argued that the sniff should use the File::getMethodParameters() method to do the parameter parsing instead. This could be done in a future iteration, but will need to be evaluated carefully for side-effects.
  • This sniff extends the PEAR FunctionDeclaration sniff. It has been verified that that sniff is not affected by this bug.

Suggested changelog entry

Fixed Squiz.Functions.MultiLineFunctionDeclaration did not skip over (parameter) attributes leading to false positives.

Related issues/external references

Fixes #608

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

The sniff looks for `T_COMMA` tokens to find the start of the next parameter and skips over parenthesis sets and square brackets sets (like short arrays) to prevent mismatching on a `T_COMMA` which is not a parameter separator.

This logic did not take parameter attributes into account, which can contain multiple comma-separated attributes, so should also be skipped over.

Fixed now. Includes plenty of tests.

Also includes minor stability fix for the parentheses/square brackets skipping.

Notes:
* It could be argued that the sniff should use the `File::getMethodParameters()` method to do the parameter parsing instead. This could be done in a future iteration, but will need to be evaluated carefully for side-effects.
* This sniff extends the PEAR `FunctionDeclaration` sniff. It has been verified that that sniff is not affected by this bug.

Fixes 608
@jrfnl jrfnl force-pushed the feature/608-squiz-multilinefunctiondeclarations-bug-fix-param-attributes branch from 0da0b78 to f39847a Compare September 14, 2024 09:30
@jrfnl
Copy link
Member Author

jrfnl commented Sep 14, 2024

Rebased without changes. Merging once the build has passed.

@jrfnl jrfnl merged commit b87dafd into master Sep 14, 2024
49 checks passed
@jrfnl jrfnl deleted the feature/608-squiz-multilinefunctiondeclarations-bug-fix-param-attributes branch September 14, 2024 09:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Squiz.Functions.MultiLineFunctionDeclaration reports error if php attributes are declared
1 participant