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

PcovEngine::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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