Conditions | 5 |
Paths | 9 |
Total Lines | 27 |
Code Lines | 14 |
Lines | 0 |
Ratio | 0 % |
Tests | 13 |
CRAP Score | 5.0592 |
Changes | 0 |
1 | <?php |
||
23 | 15 | public static function exec($command, array $params = array(), $mergeStdErr=true) |
|
24 | { |
||
25 | 15 | if (empty($command)) { |
|
26 | 3 | throw new \InvalidArgumentException('Command line is empty'); |
|
27 | } |
||
28 | |||
29 | 12 | $command = self::bindParams($command, $params); |
|
30 | |||
31 | 12 | if ($mergeStdErr) { |
|
32 | // Redirect stderr to stdout to include it in $output |
||
33 | 12 | $command .= ' 2>&1'; |
|
34 | 12 | } |
|
35 | |||
36 | 12 | exec($command, $output, $code); |
|
37 | |||
38 | 12 | if (count($output) === 0) { |
|
39 | $output = $code; |
||
40 | } else { |
||
41 | 12 | $output = implode(PHP_EOL, $output); |
|
42 | } |
||
43 | |||
44 | 12 | if ($code !== 0) { |
|
45 | 3 | throw new CommandException($command, $output, $code); |
|
46 | } |
||
47 | |||
48 | 9 | return $output; |
|
49 | } |
||
50 | |||
77 |