Completed
Push — master ( 88991f...6ec29e )
by Jakub
01:26
created

XDebugEngine::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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