| Conditions | 2 |
| Paths | 2 |
| Total Lines | 25 |
| Code Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 12 |
| CRAP Score | 2.0017 |
| Changes | 0 | ||
| 1 | <?php |
||
| 29 | 3 | public function run(string $cmd) : Result |
|
| 30 | { |
||
| 31 | 3 | $old = error_reporting(0); |
|
| 32 | $descriptorSpec = [ |
||
| 33 | 3 | ['pipe', 'r'], |
|
| 34 | ['pipe', 'w'], |
||
| 35 | ['pipe', 'w'], |
||
| 36 | ]; |
||
| 37 | |||
| 38 | 3 | $process = proc_open($cmd, $descriptorSpec, $pipes); |
|
| 39 | 3 | if (!is_resource($process)) { |
|
| 40 | throw new RuntimeException('can\'t execute \'proc_open\''); |
||
| 41 | } |
||
| 42 | |||
| 43 | 3 | $stdOut = stream_get_contents($pipes[1]); |
|
| 44 | 3 | fclose($pipes[1]); |
|
| 45 | |||
| 46 | 3 | $stdErr = stream_get_contents($pipes[2]); |
|
| 47 | 3 | fclose($pipes[2]); |
|
| 48 | |||
| 49 | 3 | $code = proc_close($process); |
|
| 50 | 3 | error_reporting($old); |
|
| 51 | |||
| 52 | 3 | return new Result($cmd, $code, $stdOut, $stdErr); |
|
| 53 | } |
||
| 54 | } |
||
| 55 |