1.2.602. Is Actually Zero

This addition actually may be simplified because one term is actually negated by another.

This kind of error happens when the expression is very large : the more terms are included, the more chances are that some auto-annihilation happens.

This error may also be a simple typo : for example, calculating the difference between two consecutive terms.

<?php

// This is quite obvious
$a = 2 - 2;

// This is obvious too. This may be a typo-ed difference between two consecutive terms.
// Could have been $c = $fx[3][4] - $fx[3][3] or $c = $fx[3][5] - $fx[3][4];
$c = $fx[3][4] - $fx[3][4];

// This is less obvious
$a = $b[3] - $c + $d->foo(1,2,3) + $c + $b[3];

?>

1.2.602.1. Suggestions

  • Clean the code and remove the null sum

  • Fix one of the variable : this expression needs another variable here

  • When adding differences, calculate the difference in a temporary variable first.

1.2.602.2. Specs

Short name

Structures/IsZero

Rulesets

All, Analyze, CE, CI-checks, Changed Behavior

Exakat since

0.12.15

PHP Version

All

Severity

Minor

Time To Fix

Instant (5 mins)

Precision

High

Examples

Dolibarr, SuiteCrm

Available in

Entreprise Edition, Community Edition, Exakat Cloud