1.2.1291. Unreadable Interval Check

When checking that a value belongs to a certain interval, the interval check should use && and not ||.

The expression should be read that $a is greater than a lower limit and lesser than an upper limit.

Expressions with || are less readable: they should be build that $a is below a lower limit, or beyond an upper limit, and that triggers the error.

<?php

//interval correctly checked a is between 2 and 999
if ($a > 1 && $a < 1000) {}

//interval incorrectly checked : a is 2 or more ($a < 1000 is never checked)
if ($a > 1 || $a < 1000) {}

?>

1.2.1291.1. Suggestions

  • Make the interval easy to read and understand

  • Check the truth table for the logical operation

1.2.1291.2. Specs

Short name

Structures/WrongRange

Rulesets

All, Analyze, Changed Behavior

Exakat since

1.2.5

PHP Version

All

Severity

Major

Time To Fix

Instant (5 mins)

Precision

Very high

Examples

Dolibarr, WordPress

Available in

Entreprise Edition, Exakat Cloud