CRITICAL
Rule Definition
Using Count function inside a loop can decrease the performance of the application, the function being called at every iteration of the loop. Instead of calling the function inside the loop it is recommended to call the function before the loop and use a variable for the value.
Remediation
Try to reduce the use of count function inside a for loop and use instead a variable having the return of the count function.
Violation Code Sample
<?php
class Test
{
public function testNames($names) {
for($counter = 0; $counter < count($names); $counter++) { //violation
if (10 < strlen($names[$counter])) { //violation
if (100 > sizeof($names)) { //violation
break;
}
}
}
}
}
$obj = new Test();
$obj->testNames(array("first name", "second name", "third name"));
?>
Related Technologies
Technical Criterion
Efficiency - Memory, Network and Disk Space Management
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.