PHPDbgBinFile   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 75%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 46
ccs 12
cts 16
cp 0.75
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 14 2
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