Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to indent a long ternary condition in Php?

I have a long ternary condition in Php that exceeds the 120 hard rule.

What would be the right indentation according to PSR standard?

This is my ternary condition. The condition is a bit long, so the function call exceeds the 120 rule.

$variable = (condition) ? function() : $variable 

Is this a valid indendation?

$variable = (condition)
    ? function()
    : $variable
like image 287
Shylajhaa Avatar asked Sep 12 '25 21:09

Shylajhaa


1 Answers

One option is to put each part on new line so it is clearly visible what you do in the "if" part and "else" part:

$variable = (condition) 
    ? function() 
    : $variable;
like image 110
Vadim Sirbu Avatar answered Sep 15 '25 10:09

Vadim Sirbu