Skip to content

no-nested-ternaryfixable

Ensure that ternary statements are not nested

Examples

  • Examples of correct code for this rule using default options

Single level ternary statements

php
<?php

// ternary example
$foo = $bar ? $baz : $qux;
echo $foo === $bar ? $baz : $qux;
  • Examples of incorrect code for this rule using default options

Multi level ternary statements

php
<?php

$foo = $bar ? $baz : $qux ? $quux : $corge;
echo ($foo ? $bar : $baz) ? $qux : $quux;

// multilevel ternary
$foo = $bar ? $baz : $qux ? $quux : $corge ? $grault : $garply;
echo ($foo ? $bar : $baz) ? $qux : $quux ? $corge : $grault;

Released under the MIT License.