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

PcovEngine::collect()   A

Complexity

Conditions 5
Paths 3

Size

Total Lines 21
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

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