NestedIf   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 8
lcom 0
cbo 0
dl 0
loc 26
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B merge() 0 23 8
1
<?php
2
3
namespace Imanghafoori\LaravelMicroscope\Refactors;
4
5
class NestedIf
6
{
7
    public static function merge($tokens, $cond1EndIndex, $cond2StartIndex, $if2BodyEndIndex)
8
    {
9
        $newTokens = [];
10
        foreach ($tokens as $i => $oldToken) {
11
            if ($i == $cond1EndIndex) {
12
                $newTokens[] = [T_WHITESPACE, ' '];
13
                $newTokens[] = [T_BOOLEAN_AND, '&&'];
14
                $newTokens[] = [T_WHITESPACE, ' '];
15
                continue;
16
            }
17
18
            if ($i > $cond1EndIndex && $i <= $cond2StartIndex) {
19
                continue;
20
            }
21
22
            if ($i == $if2BodyEndIndex || ($i == $if2BodyEndIndex + 1 && $oldToken == ';')) {
23
                continue;
24
            }
25
            $newTokens[] = $oldToken;
26
        }
27
28
        return $newTokens;
29
    }
30
}
31