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

Auto fix of Squiz.Formatting.OperatorBracket.MissingBrackets is incorrect when working with ?? operator #3930

Open
3 tasks done
leonidasmi opened this issue Nov 25, 2023 · 0 comments

Comments

@leonidasmi
Copy link

Describe the bug

The autofixer fixes the Squiz.Formatting.OperatorBracket.MissingBrackets in a specific case with the ?? operator by malrforming the existing logic:

Instead of bracketing the whole statement, it brackets part of it, thus changing the behavior of the affecting line

Code sample

'test' => $foo->prop ?? 'test_' . $bar,

becomes

'test' => ($foo->prop ?? 'test_') . $bar,

although it should have become

'test' => ($foo->prop ?? 'test_' . $bar),

if I'm not completely mistaken

To reproduce

Steps to reproduce the behavior:

  1. Create a file called test.php with the code sample above
  2. Run the autofixer
  3. Verify that you get changed behavior in the changed code.

Versions (please complete the following information)

Operating System Windows 10]
PHP version 7.4.3
PHP_CodeSniffer version [e.g., 3.5.5, master]
Standard Squiz]

Additional context

Add any other context about the problem here.

Please confirm:

  • I have searched the issue list and am not opening a duplicate issue.
  • 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant