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

PcovEngine   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 7.69%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 15
c 2
b 0
f 1
dl 0
loc 38
ccs 1
cts 13
cp 0.0769
rs 10
wmc 8

4 Methods

Rating   Name   Duplication   Size   Complexity  
A isAvailable() 0 3 1
A getName() 0 3 1
A collect() 0 21 5
A start() 0 3 1
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