NestedIf::merge()   B
last analyzed

Complexity

Conditions 8
Paths 5

Size

Total Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 23
rs 8.4444
c 0
b 0
f 0
cc 8
nc 5
nop 4
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