Skip to content

Latest commit

 

History

History
48 lines (33 loc) · 1.06 KB

ternary_to_elvis_operator.rst

File metadata and controls

48 lines (33 loc) · 1.06 KB

Rule ternary_to_elvis_operator

Use the Elvis operator ?: where possible.

Warning

Using this rule is risky

Risky when relying on functions called on both sides of the ? operator.

Examples

Example #1

--- Original
+++ New
 <?php
-$foo = $foo ? $foo : 1;
+$foo = $foo ?  : 1;

Example #2

--- Original
+++ New
-<?php $foo = $bar[a()] ? $bar[a()] : 1; # "risky" sample, "a()" only gets called once after fixing
+<?php $foo = $bar[a()] ?  : 1; # "risky" sample, "a()" only gets called once after fixing

Rule sets

The rule is part of the following rule sets:

@PhpCsFixer:risky
Using the @PhpCsFixer:risky rule set will enable the ternary_to_elvis_operator rule.
@Symfony:risky
Using the @Symfony:risky rule set will enable the ternary_to_elvis_operator rule.