Conditions | 7 |
Paths | 30 |
Total Lines | 29 |
Code Lines | 21 |
Lines | 0 |
Ratio | 0 % |
Tests | 25 |
CRAP Score | 7 |
Changes | 5 | ||
Bugs | 1 | Features | 2 |
1 | <?php |
||
17 | 4 | public function executeCommand($scriptPath, array $env = []) |
|
18 | { |
||
19 | 4 | $oldCwd = NULL; |
|
20 | 4 | if (is_array($scriptPath)) { |
|
21 | 1 | if (isset($scriptPath['cwd'])) { |
|
22 | 1 | $cwd = $scriptPath['cwd']; |
|
23 | 1 | unset($scriptPath['cwd']); |
|
24 | 1 | $oldCwd = getcwd(); |
|
25 | 1 | chdir($cwd); |
|
26 | 1 | } |
|
27 | 1 | $commands = $scriptPath; |
|
28 | 1 | } else { |
|
29 | 3 | $commands = [$scriptPath]; |
|
30 | } |
||
31 | 4 | foreach ($env as $key => $value) { |
|
32 | 4 | putenv($key . '=' . $value); |
|
33 | 4 | } |
|
34 | 4 | $result = []; |
|
35 | 4 | foreach ($commands as $command) { |
|
36 | 4 | exec($command, $result, $return); |
|
37 | 4 | if ($return !== 0) { |
|
38 | 1 | throw new ExecutionFailed('Command ' . $command . 'resulted in error: ' . $return, $return); |
|
39 | } |
||
40 | 3 | } |
|
41 | 3 | if ($oldCwd !== NULL) { |
|
42 | 1 | chdir($oldCwd); |
|
43 | 1 | } |
|
44 | 3 | return implode("\n", $result); |
|
45 | } |
||
46 | |||
48 |