testRuleApplyToNestedLoops.php ➔ testRuleApplyToNestedLoops()   C
last analyzed

Complexity

Conditions 14
Paths 6

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 14
nc 6
nop 0
dl 0
loc 22
rs 6.2666
c 0
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * This file is part of PHP Mess Detector.
4
 *
5
 * Copyright (c) Manuel Pichler <[email protected]>.
6
 * All rights reserved.
7
 *
8
 * Licensed under BSD License
9
 * For full copyright and license information, please see the LICENSE file.
10
 * Redistributions of files must retain the above copyright notice.
11
 *
12
 * @author Manuel Pichler <[email protected]>
13
 * @copyright Manuel Pichler. All rights reserved.
14
 * @license https://opensource.org/licenses/bsd-license.php BSD License
15
 * @link http://phpmd.org/
16
 */
17
18
function testRuleApplyToNestedLoops()
19
{
20
    $foo = 'foo';
21
22
    for ($i = 0; sizeof($i) < 5 || $i < 5; $i++) {
23
        while ($i !== 'baz' && count($foo) || $i < 5) {
0 ignored issues
show
Unused Code Bug introduced by
The strict comparison !== seems to always evaluate to true as the types of $i (integer) and 'baz' (string) can never be identical. Maybe you want to use a loose comparison != instead?
Loading history...
24
            $foo .= $i;
25
            do {
26
                $i += 2;
27
            } while (5 - 0 < sizeof($foo) && 3 < $foo . 'bar');
28
            while (count($foo) < 5 && sizeof($foo) < 5 && count($foo) < 5) {
29
                while (count($_GET) > -1 && 0) {
30
                    for ($j = 0; $j < count($_GET); $j++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
31
                        $i += $j * 2;
32
                    }
33
                }
34
            }
35
        }
36
    }
37
38
    return $foo;
39
}
40