Passed
Push — master ( d40832...b64ee5 )
by Jakub
01:41
created

PhpdbgEngine::isAvailable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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