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

XDebugEngine   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 14
c 1
b 0
f 1
dl 0
loc 31
rs 10
wmc 8

4 Methods

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