Completed
Push — master ( 9a7b87...ad20a3 )
by Alessandro
03:07
created

PHPDbgBinFile   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 45
ccs 0
cts 26
cp 0
rs 10
c 0
b 0
f 0

4 Methods

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