Completed
Pull Request — master (#71)
by Alessandro
07:13 queued 01:42
created

PHPDbgBinFile::isAvailable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
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 1
    public function __construct()
20
    {
21 1
        $this->phpDbgBin = $this->getPhpDbgBinLocation();
22 1
    }
23
24
    /**
25
     * @return string
26
     * @throws \Exception
27
     */
28
    public function getPhpDbgBin()
29
    {
30
        if (! $this->isAvailable()) {
31
            throw new \RuntimeException('PHPDbg is not available!');
32
        }
33
34
        return $this->phpDbgBin;
35
    }
36
37 1
    public function isAvailable()
38
    {
39 1
        return $this->phpDbgBin !== '';
40
    }
41
42
    /**
43
     * @return string
44
     */
45 1
    private function getPhpDbgBinLocation()
46
    {
47 1
        $locator = new Process('command -v phpdbg');
48 1
        $locator->run();
49
50 1
        return (string) preg_replace('/\s/', '', $locator->getOutput());
51
    }
52
}
53