Fork me on GitHub
a Sensio Labs Product

I ate three cookies πŸͺ (v3.40.2) edition

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:

Source classΒΆ

PhpCsFixer\Fixer\Operator\TernaryToElvisOperatorFixer