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

PHPDbgBinFile   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 69.23%

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 9
cts 13
cp 0.6923
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getPhpDbgBin() 0 8 2
A __construct() 0 4 1
A isAvailable() 0 4 1
A getPhpDbgBinLocation() 0 7 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