-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Conditional with missing braces confused by indirect variables #1882
Comments
It's been a week with no response, what should be my expectations? This is a definite repeatable issue where some valid code is beautified into invalid syntax. I'm not trying to be a jerk, I'm really not. I'm just curious if there's something else I should be doing to help move this along other than digging in and attempting to solve the issue myself. I'm far too unfamiliar with all of this to attempt doing that. Thanks for any help anyone can offer. |
I've seen your report and it's on my list of issues to review. I've just come back from 3 weeks being ill and my backlog is huge. I'm also catching up on my actual paying job after being away so long, so I've had very little time for PHPCS. What time I have is going into releasing the already late 3.2.3 version, which a fix for this issue will not make it into. Typically, anything that involves tokenizer issues because people have left out braces for control structures tends to be pretty tricky to resolve, so I wont get a chance to even look into this until after the next release or it will use up all my time. |
Just in case you need more example code/test cases, at WPCS we received a report about the same issue: WordPress/WordPress-Coding-Standards#1321 |
Debug output for the sample code showing how the curly brace of the variable is being incorrectly assigned as the opening brace of the second IF:
|
This turned out to be easier than I thought as there was already code to ignore braces for code like this, but it didn't support Thanks for reporting this. |
I've boiled down my issue to the following code snippet:
When I run
phpcs --standard=PSR2 filename.php
it identifies 3 errors and suggests phpcbf can fix all 3. When I run phpcbf on it the following is the result:This is not equivalent to the original code and is not even syntactically correct.
I've tried several variants of the starting code and it seems to require an outer block (could be a conditional as above or a function declaration), the inner conditional must have an inline statement, the inline statement must be on a separate line, and the inline statement must indirectly access a variable using braces to make the intent explicit.
One more quirk is if you change the
foo(...)
call to areturn(...)
the result is formatted differently but the syntax is flawed in the same way.I'm not familiar with all of the code sniffs that are being used and how they interact but it seems clear the inner conditional incorrectly finds its missing braces in the
${$a[$b]}
statement.If you need any other details please let me know.
The text was updated successfully, but these errors were encountered: