Passed
Push — master ( 492f4c...0725f5 )
by Jakub
02:01
created

XDebugEngine::collect()   A

Complexity

Conditions 5
Paths 3

Size

Total Lines 19
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 5.0342

Importance

Changes 2
Bugs 0 Features 1
Metric Value
cc 5
eloc 10
c 2
b 0
f 1
nc 3
nop 0
dl 0
loc 19
ccs 8
cts 9
cp 0.8889
crap 5.0342
rs 9.6111
1
<?php
2
declare(strict_types=1);
3
4
namespace MyTester\CodeCoverage;
5
6
/**
7
 * XDebug engine for code coverage collector
8
 *
9
 * @author Jakub Konečný
10
 * @internal
11
 */
12
final class XDebugEngine implements ICodeCoverageEngine
13
{
14
    public function getName(): string
15
    {
16 1
        return "XDebug";
17
    }
18
19
    public function isAvailable(): bool
20
    {
21 1
        return extension_loaded('xdebug');
22
    }
23
24
    public function start(): void
25
    {
26 1
        xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
27
    }
28
29
    public function collect(): array
30
    {
31 1
        $positive = $negative = [];
32
33 1
        foreach (xdebug_get_code_coverage() as $file => $lines) {
34 1
            if (!file_exists($file)) {
35
                continue;
36
            }
37
38 1
            foreach ($lines as $number => $value) {
39 1
                if ($value > 0) {
40 1
                    $positive[$file][$number] = $value;
41
                } else {
42 1
                    $negative[$file][$number] = $value;
43
                }
44
            }
45
        }
46
47 1
        return array_replace_recursive($negative, $positive);
48
    }
49
}
50