Conditions | 4 |
Paths | 6 |
Total Lines | 22 |
Code Lines | 14 |
Lines | 0 |
Ratio | 0 % |
Tests | 10 |
CRAP Score | 4.3731 |
Changes | 0 |
1 | <?php |
||
20 | 3 | public function run(int $type, string $dir, string $command, bool $sudo = false) : TempFile { |
|
21 | 3 | $tempfile = $this->tempmrg->createFile(); |
|
22 | 3 | $temp_path = $tempfile->getPath(); |
|
23 | |||
24 | 3 | $cmd = "cd " . escapeshellarg($dir) . " && "; |
|
25 | 3 | if ($sudo === true) { |
|
26 | $cmd .= "sudo "; |
||
27 | } |
||
28 | 3 | $cmd .= $command . " "; |
|
29 | 3 | $cmd .= ">> " . escapeshellarg($temp_path) . " 2>> " . escapeshellarg($temp_path) . " "; |
|
30 | |||
31 | 3 | if ($type === self::COMMAND_SYNC) { |
|
32 | |||
33 | } else if ($type === self::COMMAND_ASYNC) { |
||
34 | $cmd = "(" . $cmd . ") &"; |
||
35 | } else { |
||
36 | throw new Exception("Invalid command type"); |
||
37 | } |
||
38 | |||
39 | 3 | shell_exec($cmd); |
|
40 | |||
41 | 3 | return $tempfile; |
|
42 | } |
||
44 | } |