PHPDbgBinFile::isAvailable()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Paraunit\Configuration;
6
7
use Symfony\Component\Process\Process;
8
9
/**
10
 * Class PHPDbgBinFile
11
 * @package Paraunit\Configuration
12
 */
13
class PHPDbgBinFile
14
{
15
    /** @var string Realpath to the PHPDbg bin location */
16
    private $phpDbgBin;
17
18
    /**
19
     * PHPDbgBinFile constructor.
20
     */
21 8
    public function __construct()
22
    {
23 8
        $this->phpDbgBin = $this->getPhpDbgBinLocation();
24
    }
25
26
    /**
27
     * @return string
28
     * @throws \RuntimeException When PHPDBG is not available
29
     */
30 7
    public function getPhpDbgBin(): string
31
    {
32 7
        if (! $this->isAvailable()) {
33
            throw new \RuntimeException('PHPDbg is not available!');
34
        }
35
36 7
        return $this->phpDbgBin;
37
    }
38
39 8
    public function isAvailable(): bool
40
    {
41 8
        return $this->phpDbgBin !== '';
42
    }
43
44 8
    private function getPhpDbgBinLocation(): string
45
    {
46 8
        $checkInPath = new Process(['phpdbg', '--version']);
47 8
        $checkInPath->run();
48 8
49 8
        if ($checkInPath->getExitCode() === 0) {
50
            return 'phpdbg';
51
        }
52
53
        $locator = new Process(['command', '-v', 'phpdbg']);
54
        $locator->run();
55
56
        return preg_replace('/\s/', '', $locator->getOutput());
57
    }
58
}
59