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.ControlStructures.ControlSignature does not handle alt syntax when checking space after closing brace #1387

Closed
LC43 opened this issue Mar 12, 2017 · 3 comments

Comments

@LC43
Copy link
Contributor

LC43 commented Mar 12, 2017

Hi, thanks for your work! I have a question, which I think is a bug:

closing a brace inside a another if that uses the alternative syntax:

$a = 1;
if (1 === $a) :
    if ($b) {
        echo 'b';
    } else {
        $something = 'not b';
    }
else :
    echo 'not 1';
endif;

Error:

$ phpcs --report-full --standard=PSR2 test-alternate.php
----------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
----------------------------------------------------------------------
 8 | ERROR | [x] Expected 1 space after closing brace; newline found
----------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------

using this code, i found that phpcs fails on the line 8 }. It shouldn't consider the next line as the continuation of the inner control structure.

adding a new line between } and else : removes the error message:

    }
    $b = 1;
else :

I inherit the code, so I just replaced the syntax. But on other occasions, should I follow the advice on #347 and use custom ruleset or is this a bug?

this is a gist with both blocks. It fails on the first and passes the second:

https://gist.github.com/LC43/383ff51e169b9b113cdb750dbcdcf25b

thank you.

@gsherwood
Copy link
Member

This looks like a bug in the sniff to me. The core tokenizer has processed this code structure correctly, but the sniff is confused by the fact that else is both the closing point for the if and the opening point for itself.

@gsherwood gsherwood changed the title Expected 1 space after closing brace; newline found Squiz.ControlStructures.ControlSignature does not handle alt syntax when checking space after closing brace Mar 13, 2017
gsherwood added a commit that referenced this issue Mar 13, 2017
…andle alt syntax when checking space after closing brace
@gsherwood
Copy link
Member

This has been fixed now. There wont be any errors reported for that code when using PSR2. Thanks for reporting this.

@LC43
Copy link
Contributor Author

LC43 commented Mar 13, 2017

wow! impressive @gsherwood, thank you so much for your fast fix!

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