Completed
Push — master ( 1a3a48...6e0e69 )
by Alessandro
09:39 queued 07: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 75%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 0
loc 45
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 13 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 4
    public function __construct()
22
    {
23 4
        $this->phpDbgBin = $this->getPhpDbgBinLocation();
24
    }
25
26
    /**
27
     * @return string
28
     * @throws \RuntimeException When PHPDBG is not available
29
     */
30 3
    public function getPhpDbgBin(): string
31
    {
32 3
        if (! $this->isAvailable()) {
33
            throw new \RuntimeException('PHPDbg is not available!');
34
        }
35
36 3
        return $this->phpDbgBin;
37
    }
38
39 4
    public function isAvailable(): bool
40
    {
41 4
        return $this->phpDbgBin !== '';
42
    }
43
44 4
    private function getPhpDbgBinLocation(): string
45
    {
46 4
        $checkInPath = new Process('phpdbg --version');
47 4
        $checkInPath->run();
48 4
        if ($checkInPath->getExitCode() === 0) {
49 4
            return 'phpdbg';
50
        }
51
52
        $locator = new Process('command -v phpdbg');
53
        $locator->run();
54
55
        return (string) preg_replace('/\s/', '', $locator->getOutput());
56
    }
57
}
58