Are parentheses required in PSR-2 PHP ternary syntax?

后端 未结 5 1217
春和景丽
春和景丽 2021-02-13 20:13

Question: are parentheses required in PSR-2 PHP ternary syntax?

Looking for which (if either) of the following ternary statement\'s syntax is compliant with PSR-2 - I

5条回答
  •  一个人的身影
    2021-02-13 21:10

    One important thing to keep in mind is that PSR-2 states that lines SHOULD NOT be longer than 80 characters.
    The ternary syntax can be pretty long sometimes, so I think we have a missing recommendation for a very common kind of code. What I'm doing currently is indent it like this:

    $stuff = $count > MyLongNamespace\MyLongClassName->get('count') 
        ? 'yikes this seems to be some large stuff'
        : 'erm this is rather small stuff';
    

提交回复
热议问题