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/DisallowMultipleAssignments: false positive when checking for default values and function is missing the closing parenthesis #551

Closed
4 tasks done
rodrigoprimo opened this issue Jul 15, 2024 · 2 comments · Fixed by #557

Comments

@rodrigoprimo
Copy link
Contributor

Describe the bug

While reviewing #538, I found another false positive in Squiz.PHP.DisallowMultipleAssignments when the code checks for default values. If the function is missing the closing parenthesis (which is a parse error but could happen during live coding), the sniff will incorrectly throw an error.

I will open a PR to fix this error once #538 is merged to avoid conflicts.

Code sample

<?php

function missingClosingParenthesis($a =

To reproduce

Steps to reproduce the behavior:

  1. Create a file called test.php with the code sample above.
  2. Run phpcs test.php --standard=Squiz --sniffs=Squiz.PHP.DisallowMultipleAssignments test.php
  3. See error message displayed

FILE: test.php
----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
 3 | ERROR | Assignments must be the first block of code on a line
----------------------------------------------------------------------

Expected behavior

The sniff should bail early if the function is missing the closing parenthesis instead of producing an error.

Versions (please complete the following information)

Operating System Ubuntu 24.04
PHP version 8.3
PHP_CodeSniffer version master
Standard Squiz
Install type git clone

Please confirm

  • I have searched the issue list and am not opening a duplicate issue.
  • I have read the Contribution Guidelines and this is not a support question.
  • I confirm that this bug is a bug in PHP_CodeSniffer and not in one of the external standards.
  • I have verified the issue still exists in the master branch of PHP_CodeSniffer.
@jrfnl
Copy link
Member

jrfnl commented Jul 15, 2024

@rodrigoprimo I've merged PR #538, feel free to rebase & submit your fix PR.

@rodrigoprimo
Copy link
Contributor Author

rodrigoprimo commented Jul 16, 2024

Thanks, @jrfnl. I just submitted the PR: #557.

@jrfnl jrfnl added this to the 3.10.x Next milestone Jul 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment