| 148 |
lars |
1 |
<?php declare(strict_types=1);
|
|
|
2 |
/*
|
|
|
3 |
* This file is part of phpunit/php-code-coverage.
|
|
|
4 |
*
|
|
|
5 |
* (c) Sebastian Bergmann <sebastian@phpunit.de>
|
|
|
6 |
*
|
|
|
7 |
* For the full copyright and license information, please view the LICENSE
|
|
|
8 |
* file that was distributed with this source code.
|
|
|
9 |
*/
|
|
|
10 |
namespace SebastianBergmann\CodeCoverage\Driver;
|
|
|
11 |
|
|
|
12 |
use function phpversion;
|
|
|
13 |
use function version_compare;
|
|
|
14 |
use SebastianBergmann\CodeCoverage\Filter;
|
|
|
15 |
use SebastianBergmann\CodeCoverage\NoCodeCoverageDriverAvailableException;
|
|
|
16 |
use SebastianBergmann\CodeCoverage\NoCodeCoverageDriverWithPathCoverageSupportAvailableException;
|
|
|
17 |
use SebastianBergmann\Environment\Runtime;
|
|
|
18 |
|
|
|
19 |
final class Selector
|
|
|
20 |
{
|
|
|
21 |
/**
|
|
|
22 |
* @throws NoCodeCoverageDriverAvailableException
|
|
|
23 |
* @throws PcovNotAvailableException
|
|
|
24 |
* @throws PhpdbgNotAvailableException
|
|
|
25 |
* @throws Xdebug2NotEnabledException
|
|
|
26 |
* @throws Xdebug3NotEnabledException
|
|
|
27 |
* @throws XdebugNotAvailableException
|
|
|
28 |
*/
|
|
|
29 |
public function forLineCoverage(Filter $filter): Driver
|
|
|
30 |
{
|
|
|
31 |
$runtime = new Runtime;
|
|
|
32 |
|
|
|
33 |
if ($runtime->hasPHPDBGCodeCoverage()) {
|
|
|
34 |
return new PhpdbgDriver;
|
|
|
35 |
}
|
|
|
36 |
|
|
|
37 |
if ($runtime->hasPCOV()) {
|
|
|
38 |
return new PcovDriver($filter);
|
|
|
39 |
}
|
|
|
40 |
|
|
|
41 |
if ($runtime->hasXdebug()) {
|
|
|
42 |
if (version_compare(phpversion('xdebug'), '3', '>=')) {
|
|
|
43 |
$driver = new Xdebug3Driver($filter);
|
|
|
44 |
} else {
|
|
|
45 |
$driver = new Xdebug2Driver($filter);
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
$driver->enableDeadCodeDetection();
|
|
|
49 |
|
|
|
50 |
return $driver;
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
throw new NoCodeCoverageDriverAvailableException;
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
/**
|
|
|
57 |
* @throws NoCodeCoverageDriverWithPathCoverageSupportAvailableException
|
|
|
58 |
* @throws Xdebug2NotEnabledException
|
|
|
59 |
* @throws Xdebug3NotEnabledException
|
|
|
60 |
* @throws XdebugNotAvailableException
|
|
|
61 |
*/
|
|
|
62 |
public function forLineAndPathCoverage(Filter $filter): Driver
|
|
|
63 |
{
|
|
|
64 |
if ((new Runtime)->hasXdebug()) {
|
|
|
65 |
if (version_compare(phpversion('xdebug'), '3', '>=')) {
|
|
|
66 |
$driver = new Xdebug3Driver($filter);
|
|
|
67 |
} else {
|
|
|
68 |
$driver = new Xdebug2Driver($filter);
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
$driver->enableDeadCodeDetection();
|
|
|
72 |
$driver->enableBranchAndPathCoverage();
|
|
|
73 |
|
|
|
74 |
return $driver;
|
|
|
75 |
}
|
|
|
76 |
|
|
|
77 |
throw new NoCodeCoverageDriverWithPathCoverageSupportAvailableException;
|
|
|
78 |
}
|
|
|
79 |
}
|