1.2.738. Multiple Similar Calls

Several calls are made to functions or methods in a row. They may have different arguments, though having a lot of similar calls in a row may indicate that a loop is needed.

Alternatively, some native PHP functions use an arbitrary number of arguments to avoid multiple calls to the same function. For example, it is possible to call array_merge() once, or a loop on .= may be replaced with a call to implode().

<?php

echo $a[1];
echo $a[2];
echo $a[3];
echo $a[4];
echo $a[5];

// This could be
foreach($a as $v) {
    echo $v;
}

if (isset($a) && isset($b) && isset($c) && isset($d)) { }

// This could be coded as
if (isset($a, $b, $c, $d)) { }

?>

1.2.738.1. Suggestions

  • Move the calls to a loop

  • Tactically use one call to a function with multiple arguments. For example, isset() with multiple arguments.

1.2.738.2. Specs

Short name

Structures/MultipleSimilarCalls

Rulesets

All, Changed Behavior, Suggestions

Exakat since

2.3.5

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

Very high

Available in

Entreprise Edition, Exakat Cloud