Skip to content

Commit 5c938e4

Browse files
committed
XdebugFileDriver
1 parent f6b94b5 commit 5c938e4

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

src/Driver/XdebugFileDriver.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
namespace SebastianBergmann\PHPCOV;
3+
4+
use SebastianBergmann\CodeCoverage\Driver\Driver;
5+
use SebastianBergmann\CodeCoverage\RawCodeCoverageData;
6+
7+
final class XdebugFileDriver extends Driver
8+
{
9+
public function __construct($fileName, $mapFrom = "", $mapTo = "")
10+
{
11+
$this->data = array();
12+
13+
foreach(json_decode(file_get_contents($fileName), true) as $key => $value) {
14+
$this->data[str_replace($mapFrom, $mapTo, $key)] = $value;
15+
}
16+
}
17+
18+
public function canCollectBranchAndPathCoverage(): bool
19+
{
20+
return true;
21+
}
22+
23+
public function canDetectDeadCode(): bool
24+
{
25+
return true;
26+
}
27+
28+
public function start(): void
29+
{
30+
}
31+
32+
public function stop(): RawCodeCoverageData
33+
{
34+
if ($this->collectsBranchAndPathCoverage()) {
35+
return RawCodeCoverageData::fromXdebugWithPathCoverage($this->data);
36+
}
37+
38+
return RawCodeCoverageData::fromXdebugWithoutPathCoverage($this->data);
39+
}
40+
41+
public function nameAndVersion(): string
42+
{
43+
return 'Xdebug file driver';
44+
}
45+
}

0 commit comments

Comments
 (0)