-
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
Incorrect detection of operator in ternary + anonymous function #1782
Comments
If I put both your code examples into a file like this: <?php
$x = $foo
? function (): int {
return 1;
}
: $bar;
$x = !$foo
? $bar
: function (): int {
return 1;
}; And then run PHPCS, I get errors for both colons:
I'm using PHPCS version 3.2.0, but I also tried 2.9.1. What version are you using? |
@gsherwood I think the op intended to point out that the return type specifier colon The return type specifier colon is not an operator and IMO should not be covered by the Fixing the tokenizing issue, should get rid of the incorrect sniff result the op reported. |
Sorry, was in a a hurry and forgot to mention the version, I tested it both on Yes I think it is excatly as @jrfnl writes, the problem seems to be in tokenization rather than the sniff, I showed the two examples because it further suggests that the tokenization is broken only when the anon function is in the true part of the ternary, suggesting the detection of the You can filter out the unrelated errors with (I have this in the ruleset, sorry for not including it):
|
Sorry, I missed the tokenizing issue. Makes sense now. Thanks. |
I've fixed up the tokenizer, although it was a bit painful. I can't think of a better way of detecting the colon though, given PHP doesn't assign them different tokens. Thanks for reporting this issue. |
Thank you! :) |
I think there is a problem with detection of the
:
operator in ternary in combination with a function. I found this out while usingSquiz.WhiteSpace.OperatorSpacing
, but it can be more general.This case throws error:
while just inverting the condition is ok:
The text was updated successfully, but these errors were encountered: