Passed
Push — master ( 146be5...1e12ef )
by ANTHONIUS
06:12
created

Runtime::hasPCOV()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 1
nc 3
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the doyo/code-coverage project.
5
 *
6
 * (c) Anthonius Munthi <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
14
namespace Doyo\Bridge\CodeCoverage\Environment;
15
16
use Doyo\Bridge\CodeCoverage\Driver\Dummy;
17
use Doyo\Bridge\CodeCoverage\Driver\PCOV;
18
use SebastianBergmann\CodeCoverage\Driver\HHVM;
0 ignored issues
show
Bug introduced by
The type SebastianBergmann\CodeCoverage\Driver\HHVM was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
19
use SebastianBergmann\CodeCoverage\Driver\PHPDBG;
20
use SebastianBergmann\CodeCoverage\Driver\Xdebug;
21
use SebastianBergmann\Environment\Runtime as RuntimeEnvironment;
22
23
/**
24
 * Class Runtime.
25
 *
26
 * @method bool isHHVM()
27
 * @method bool isPHPDBG()
28
 * @method bool hasXdebug()
29
 * @method bool hasPHPDBGCodeCoverage()
30
 * @method bool isPHP()
31
 */
32
final class Runtime implements RuntimeInterface
33
{
34
    private $runtime;
35
36 21
    public function __construct()
37
    {
38 21
        $this->runtime = new RuntimeEnvironment();
39
    }
40
41 21
    public function getDriverClass(): string
42
    {
43 21
        $driverClass = Dummy::class;
44
45
        // @codeCoverageIgnoreStart
46
        if ($this->isHHVM()) {
47
            $driverClass = HHVM::class;
48
        }
49
50
        if ($this->isPHPDBG()) {
51
            $driverClass = PHPDBG::class;
52
        }
53
54
        if (
55
            version_compare(PHP_VERSION, '7.0', '>')
56
            && $this->hasPCOV()
57
        ){
58
            //$driverClass = PCOV::class;
59
        }
60
61
        if ($this->hasXdebug()) {
62
            $driverClass =  Xdebug::class;
63
        }
64
        // @codeCoverageIgnoreEnd
65
66 21
        return $driverClass;
67
    }
68
69 97
    public function hasPCOV()
70
    {
71 97
        return $this->isPHP() && \extension_loaded('pcov') && \ini_get('pcov.enabled');
72
    }
73
74
    /**
75
     * Returns true when Xdebug is supported or
76
     * the runtime used is PHPDBG.
77
     */
78 97
    public function canCollectCodeCoverage(): bool
79
    {
80 97
        return $this->hasXdebug() || $this->hasPCOV() || $this->hasPHPDBGCodeCoverage();
81
    }
82
83 97
    public function __call($name, $arguments)
84
    {
85 97
        return \call_user_func_array([$this->runtime, $name], $arguments);
86
    }
87
}
88