1.2.1044. Return True False

These conditional expressions return true/false, depending on the condition. This may be simplified by dropping the control structure altogether.

This may be simplified with : This may be applied to assignations and ternary operators too.

<?php

if (version_compare($a, $b) >= 0) {
    return true;
} else {
    return false;
}

?>

1.2.1044.1. Suggestions

  • Return directly the comparison, without using the if/then structure

  • Cast the value to (boolean) and use it instead of the ternary

1.2.1044.2. Specs

Short name

Structures/ReturnTrueFalse

Rulesets

All, Analyze, CE, CI-checks

Exakat since

0.8.4

PHP Version

All

Severity

Major

Time To Fix

Quick (30 mins)

Precision

Very high

Features

boolean

Examples

Mautic, FuelCMS

Available in

Entreprise Edition, Community Edition, Exakat Cloud