1.2.1380. Useless Coalesce

The ?: operator needs the condition to be potentially empty. This means that the type should have the possibility to be null, false, 0, or any of the empty values.

<?php

function foo(A $a, bool $b) {
     $a ?: 'a';
     $b ?: 'a';
}

?>

1.2.1380.1. Suggestions

  • Remove the operator.

  • Extend the type to include values that may be empty.

1.2.1380.2. Specs

Short name

Structures/UselessCoalesce

Rulesets

All, Analyze, Changed Behavior

Exakat since

2.6.6

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

High

Available in

Entreprise Edition, Exakat Cloud