Passed
Push — master ( 11230f...5f5cdb )
by Jakub
12:32
created

XDebugEngine::collect()   A

Complexity

Conditions 5
Paths 3

Size

Total Lines 19
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 5.025

Importance

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