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

PcovEngine::isAvailable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 2
b 0
f 1
nc 1
nop 0
dl 0
loc 3
ccs 1
cts 1
cp 1
crap 1
rs 10
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