1.2.198. Common Alternatives

In the following conditional structures, expressions were found that are common to both ‘then’ and ‘else’. It may be interesting, though not always possible, to put them both out of the conditional, and reduce line count.

may be rewritten in :

<?php
if ($c == 5) {
    $b = strtolower($b[2]);
    $a++;
} else {
    $b = strtolower($b[2]);
    $b++;
}
?>

1.2.198.1. Suggestions

  • Collect common expressions, and move them before of after the if/then expression.

  • Move a prefix and suffixes to a third-party method

1.2.198.2. Specs

Short name

Structures/CommonAlternatives

Rulesets

All, Analyze

Exakat since

0.8.4

PHP Version

All

Severity

Major

Time To Fix

Instant (5 mins)

Precision

Very high

Examples

Dolibarr, NextCloud

Available in

Entreprise Edition, Exakat Cloud