testRuleAppliesToMultilevelIfConditions.php ➔ testRuleAppliesToMultilevelIfConditions()   D
last analyzed

Complexity

Conditions 22
Paths 24

Size

Total Lines 33

Duplication

Lines 3
Ratio 9.09 %

Importance

Changes 0
Metric Value
cc 22
nc 24
nop 0
dl 3
loc 33
rs 4.1666
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 testRuleAppliesToMultilevelIfConditions()
19
{
20
    if (1 || 0) { // not applied
21
        if (1 == 1 || $foo = 'baz') { // applied
22
            // ...
23
        } elseif (1 != array() && 'foo' != 'baz' && $bar = 'baz') { // applied
24
            // ...
25
        } elseif (1 % 2 !== !false && $baz = 1 + 1 + 1 - 3) { // applied
26
            // ...
27
            if ($foo == 'baz') { // not applied
28
                // ...
29
                if (3 - 2 == 3) { // not applied
30
                    // ...
31
                    if (true) { // not applied
32
                        // ...
33
                        if (1) { // not applied
34
                            // ...
35
                        } elseif ($foo = 1) { // applied
0 ignored issues
show
Unused Code introduced by
$foo is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
36
                            // ...
37
                        } elseif ($foo = 2) { // applied
0 ignored issues
show
Unused Code introduced by
$foo is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
38
                            // ...
39
                        } elseif (5 % 5 == 0) { // not applied
40
                            // ...
41
                        }
42
                    }
43
                }
44
            }
45
        }
46
    }
47 View Code Duplication
    if (1 == 1 || 1 && 0 and 4 % 2 || ($foo = 1) xor 5 * 4 * 3 * 2 * 1) { // applied
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
48
        // ...
49
    }
50
}
51