-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
elseif
vs else if
node structure
#948
Comments
It's not difficult, but then I'll get complaints that the distinction between elseif and else if gets lost ;) You should be able to easily print these without the extra nesting, like this: PHP-Parser/lib/PhpParser/PrettyPrinter/Standard.php Lines 893 to 896 in f5adbb5
|
Man, I hear you. :-)
Excellent, I will try that -- thanks! |
Thanks @nikic that did the trick. |
Update: it turns out that was not quite enough. When something like this occurs ... if (true) {
if (true) {
// foo
} else {
// bar
}
} else {
if (true) {
// baz
} else {
// dib
}
} ... the final else (with Instead, this mitigation seems to handle it properly (no disappearing if (
count($node->stmts) === 1
&& $node->stmts[0] instanceof Stmt\If_
&& ! $node->stmts[0]->elseifs
&& ! $node->stmts[0]->else
) {
// treat as `elseif`
} Thanks again for the help, and for this project. |
Fyi we tried similar things in phpstan, but all suggested solutions until now did not work in all cases. |
@staabm Thanks for that -- so, no reliable solution? |
Until now, I think no reliable solution, right. |
All right, I may have to go back to pmjones/php-styler#4 and tell him there's nothing to do, other than manually change |
This came up in pmjones/php-styler#4 earlier today. PHP-Styler rebuilds this original code using
else if
:...to this:
This is because PHP-Parser sees a second
If_
as part of theElse_
, rather than anElseif_
that is part of theIf_
.How difficult would it be for PHP-Parser to recognize
else if
aselseif
in these conditions? (My guess is that it would involve substantial effort.)The text was updated successfully, but these errors were encountered: