-
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
Multiline ternaries not being indented correctly #3711
Comments
I suggest this issue is a candidate to be closed with no action required. Multi-line ternaries are poor readability and although PSR-12 - 6.3 Ternary Operators does not explicitly mention multi-line ternaries it certainly doesn't use any in it's examples. I'm sure consensus opinion would be against breaking them onto multiple lines. If you want a multi-line conditional, use an if-statement or a Also, the ternary in your code sample is redundant and can be re-written as: $x = $a === $b; Ternaries are elegant for cases where the code blocks are so small they would look silly in an if-statement and would definitely read better were it all on 1 line such as this: $color = $accountBalance < 0 ? 'red' : 'black'; But they are inappropriate in any other situation. Only my opinion, I hope you understand. I'm just hoping that with my input, a few low-priority requests can be closed and allow some higher priority ones to get fixed. |
Not indenting them at all makes it worse, though. The pear style also has examples of indenting them: https://pear.php.net/pepr/pepr-proposal-show.php?id=538#toc5 If this is not officially taken up to get supported, is there a way of automatically disabling the sniff on ternary statements so that the user can at least manually keep indentation here? |
The simple solution here is to set the The |
I also need to have this fixed. |
@roslov This has already been marked as |
Describe the bug
phpcbf will format multiline ternaries to the same level of indentation, instead of having the lines after the first indented an additional level.
Code sample
Custom ruleset
To reproduce
Steps to reproduce the behavior:
test.php
with the code sample above...phpcs test.php ...
Expected behavior
Multiline ternaries should be indented
Versions (please complete the following information):
Additional context
n/a
The text was updated successfully, but these errors were encountered: