1.2.60. Avoid Compare Typed Boolean

There is no need to compare explicitly a function call to a boolean, when the definition has a boolean return type.

The analysis checks for equality and identity comparisons. It doesn’t check for the not operator usage.

<?php

// Sufficient check
if (foo()) {
    doSomething();
}

// Superfluous check
if (foo() === true) {
    doSomething();
}

function foo() : bool {}

?>

1.2.60.1. Suggestions

  • Simplify the code and make it short

1.2.60.2. Specs

Short name

Structures/DontCompareTypedBoolean

Rulesets

All, Suggestions

Exakat since

2.1.5

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

High

Available in

Entreprise Edition, Exakat Cloud