Processor::execute()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
c 0
b 0
f 0
rs 9.4285
cc 2
eloc 10
nc 2
nop 1
1
<?php
2
namespace Genkgo\Srvcleaner\Util;
3
4
use Genkgo\Srvcleaner\Exceptions\ProcessException;
5
use Symfony\Component\Process\Process;
6
7
/**
8
 * Class Processor
9
 * @package Genkgo\Srvcleaner\Util
10
 */
11
class Processor
12
{
13
    /**
14
     * @var
15
     */
16
    private $currentWorkingDirectory;
17
18
    /**
19
     * @return mixed
20
     */
21
    public function getCurrentWorkingDirectory()
22
    {
23
        return $this->currentWorkingDirectory;
24
    }
25
26
    /**
27
     * @param mixed $currentWorkingDirectory
28
     */
29
    public function setCurrentWorkingDirectory($currentWorkingDirectory)
30
    {
31
        $this->currentWorkingDirectory = $currentWorkingDirectory;
32
    }
33
34
    /**
35
     * @param $command
36
     */
37
    public function execute($command)
38
    {
39
        $cwd = getcwd();
40
        chdir($this->currentWorkingDirectory);
41
        $process = new Process($command);
42
        $process->enableOutput();
43
        $process->run();
44
        if (!$process->isSuccessful()) {
45
            chdir($cwd);
46
            throw new ProcessException($process->getErrorOutput());
47
        }
48
        chdir($cwd);
49
    }
50
}
51