forked from sebastianbergmann/php-code-coverage
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDriver.php
More file actions
99 lines (82 loc) · 2.78 KB
/
Copy pathDriver.php
File metadata and controls
99 lines (82 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php declare(strict_types=1);
/*
* This file is part of phpunit/php-code-coverage.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace SebastianBergmann\CodeCoverage\Driver;
use function sprintf;
use SebastianBergmann\CodeCoverage\BranchCoverageNotSupportedException;
use SebastianBergmann\CodeCoverage\Data\RawCodeCoverageData;
use SebastianBergmann\CodeCoverage\PathCoverageNotSupportedException;
/**
* @internal This class is not covered by the backward compatibility promise for phpunit/php-code-coverage
*
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for phpunit/php-code-coverage
*/
abstract class Driver
{
/**
* @see http://xdebug.org/docs/code_coverage
*/
public const int LINE_NOT_EXECUTABLE = -2;
/**
* @see http://xdebug.org/docs/code_coverage
*/
public const int LINE_NOT_EXECUTED = -1;
/**
* @see http://xdebug.org/docs/code_coverage
*/
public const int LINE_EXECUTED = 1;
/**
* @see http://xdebug.org/docs/code_coverage
*/
public const int BRANCH_NOT_HIT = 0;
/**
* @see http://xdebug.org/docs/code_coverage
*/
public const int BRANCH_HIT = 1;
private Granularity $granularity = Granularity::Line;
public function granularity(): Granularity
{
return $this->granularity;
}
/**
* @throws BranchCoverageNotSupportedException
* @throws PathCoverageNotSupportedException
*/
public function setGranularity(Granularity $granularity): void
{
if (($granularity === Granularity::LineAndBranch || $granularity === Granularity::LineBranchAndPath) &&
!$this->canCollectBranchCoverage()) {
throw new BranchCoverageNotSupportedException(
sprintf('%s does not support branch coverage', $this->nameAndVersion()),
);
}
if ($granularity === Granularity::LineBranchAndPath && !$this->canCollectPathCoverage()) {
throw new PathCoverageNotSupportedException(
sprintf('%s does not support path coverage', $this->nameAndVersion()),
);
}
$this->granularity = $granularity;
}
abstract public function name(): string;
abstract public function version(): string;
public function nameAndVersion(): string
{
return $this->name() . ' ' . $this->version();
}
abstract public function start(): void;
abstract public function stop(): RawCodeCoverageData;
protected function canCollectBranchCoverage(): bool
{
return false;
}
protected function canCollectPathCoverage(): bool
{
return false;
}
}