Search code examples
phpphpstorm

Align subsequent ternary operators in PhpStorm


Is there a way in PhpStorm to align subsequent ternary operators so that the ? (question marks) and the : (colons) are under each other?

Expected output:

$foo = empty($var)         ? 'default_value'     : $var;
$bar = empty($another_var) ? 'default_value_two' : $another_var;

The only option I see in File->Settings->Editor->Code Style->PHP->Wrapping and Braces that is related to ternary operators (by the end) is about single line -and wrapping it- and not about having multiple aligned in relation to each other.


To give a bit of perspective, the option that's called Alignment statement->Align consecutive assignments (if checked) produces this result:

$foo          = 'some value';
$another_name = 'another_value';

So, is there a way to make PhpStorm align the ternary operators in such manner?

I'm using PhpStorm 2017.2.1


Solution

  • That is not possible .. and at the moment is not even planned for any specific version (based on "Backlog" status of the corresponding ticket).

    https://youtrack.jetbrains.com/issue/WI-17880 -- watch this ticket (star/vote/comment) to get notified on any progress.