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

PSR12.ControlStructures.BooleanOperatorPlacement false positive when operator is the only content on line #3075

Closed
morozov opened this issue Sep 1, 2020 · 2 comments
Milestone

Comments

@morozov
Copy link
Contributor

morozov commented Sep 1, 2020

Describe the bug
A fixable rule violation is cannot be auto-fixed.

Code sample

<?php

function test($value)
{
    if (
        ($value == 1 ||
            $value == 2)
        &&
        ($value == 3 ||
            $value == 4)
    ) {
        return 5;
    }

    return 6;
}

Custom ruleset
None.

To reproduce
Steps to reproduce the behavior:

  1. Run phpcs -s --standard=PSR12 test.php
FILE: /home/morozov/Projects/phpcs-playground/test.php
------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
------------------------------------------------------------------------------------------------
 5 | ERROR | [x] Boolean operators between conditions must be at the beginning or end of the
   |       |     line, but not both
   |       |     (PSR12.ControlStructures.BooleanOperatorPlacement.FoundMixed)
------------------------------------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
------------------------------------------------------------------------------------------------

Time: 44ms; Memory: 6MB
  1. Run phpcbf --standard=PSR12 test.php
PHPCBF RESULT SUMMARY
----------------------------------------------------------------------
FILE                                                  FIXED  REMAINING
----------------------------------------------------------------------
/home/morozov/Projects/phpcs-playground/test.php      FAILED TO FIX
----------------------------------------------------------------------
A TOTAL OF 0 ERRORS WERE FIXED IN 1 FILE
----------------------------------------------------------------------
PHPCBF FAILED TO FIX 1 FILE
----------------------------------------------------------------------

Time: 46ms; Memory: 6MB

Expected behavior
The violation is fixed.

Versions (please complete the following information):

  • OS: Linux
  • PHP: 7.4.9
  • PHPCS: 3.5.6
  • Standard: Squiz
@gsherwood
Copy link
Member

Looks to be an issue caused by the operator being the only content on the line. There is nothing to fix here as all operators are the last content on the line, so the error shouldn't be showing at all.

@gsherwood gsherwood added this to the 3.5.7 milestone Sep 25, 2020
@gsherwood gsherwood changed the title Failed to fix a fixable PSR12.ControlStructures.BooleanOperatorPlacement.FoundMixed violation PSR12.ControlStructures.BooleanOperatorPlacement false positive when operator is the only content on line Sep 27, 2020
gsherwood added a commit that referenced this issue Sep 27, 2020
…lse positive when operator is the only content on line
gsherwood added a commit that referenced this issue Sep 27, 2020
…lse positive when operator is the only content on line
@gsherwood
Copy link
Member

Thanks for reporting this. A fix has been committed and will be released in version 3.5.7

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

2 participants