Completed
Push — master ( 400051...4d5855 )
by Alessandro
07:06
created

PHPDbgBinFile   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 92.31%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 42
ccs 12
cts 13
cp 0.9231
rs 10

4 Methods

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