Completed
Branch code-coverage (571de7)
by Jakub
02:21
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
final class XDebugEngine implements \MyTester\ICodeCoverageEngine {
7
  public function getName(): string {
8
    return "XDebug";
9
  }
10
11
  public function isAvailable(): bool {
12
    return extension_loaded('xdebug');
13
  }
14
15
  public function start(): void {
16
    xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
17
  }
18
19
  public function collect(): array {
20
    $positive = $negative = [];
21
22
    foreach(xdebug_get_code_coverage() as $file => $lines) {
23
      if(!file_exists($file)) {
24
        continue;
25
      }
26
27
      foreach($lines as $number => $value) {
28
        if($value > 0) {
29
          $positive[$file][$number] = $value;
30
        } else {
31
          $negative[$file][$number] = $value;
32
        }
33
      }
34
    }
35
36
    return [$positive, $negative,];
37
  }
38
}
39
?>