Closed roslov closed 5 months ago
Your example is very specific to your personal choice to use ternaries on multiple lines. There is nothing fundamentally wrong with the sniff and it would not be a good investment of the maintainers time to change the behaviour just for you.
Rewriting your code below not only brings the ternary onto a single line but it gives a name to the array of ISO codes and thus makes it more expressive and easier to read:
$actCountries = ['PT', 'MX', 'ES', 'IT', 'LV', 'LT', 'DK', 'CH', 'CZ'];
$where .= in_array($cISO, $actCountries, true) ? ' and cc.is_act=1' : ' and cc.is_vis=1';
If you still insist on using long ternaries on multiple lines, maybe consider if using a standards library is the right choice for you.
Open source maintainers time is precious and they have bigger fish to fry. Please understand, I only comment out of a desire to protect the CodeSniffer project and keep it sustainable.
@martinjoiner, probably you’re right regarding the current implementation of the Generic.WhiteSpace.ScopeIndent
rule. Anyway, some IDEs (like PHPStorm) do such an indentation. Maybe, there exists a third party sniff that does what I what. But I still haven’t found it :-( @martinjoiner, if you know something about such a sniff, I’d be grateful if you let me know. Thank you for your comment.
For these case, I will disable exact indentation for ternaries and multiline strings.
Disabled the exact indentation for ternaries and multiline strings by #40.
This
fails and is fixed to
It can be fixed by
But it also allows
that is not good.
See also https://github.com/squizlabs/PHP_CodeSniffer/issues/3711