| Conditions | 8 |
| Paths | 42 |
| Total Lines | 40 |
| Code Lines | 25 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 17 | public function run(CodeBlock $codeBlock): array |
||
| 18 | { |
||
| 19 | $outcomes = []; |
||
| 20 | |||
| 21 | ob_start(); |
||
| 22 | |||
| 23 | try { |
||
| 24 | $returnValue = null; |
||
| 25 | |||
| 26 | try { |
||
| 27 | $lastErrorBefore = error_get_last(); |
||
| 28 | $returnValue = @eval($codeBlock); |
||
| 29 | $lastErrorAfter = error_get_last(); |
||
| 30 | if ($lastErrorBefore != $lastErrorAfter) { |
||
| 31 | $outcomes[] = new ErrorOutcome("{$lastErrorAfter['type']}: {$lastErrorAfter['message']}"); |
||
| 32 | } |
||
| 33 | } catch (\Error $e) { |
||
| 34 | $outcomes[] = new ErrorOutcome((string)$e); |
||
| 35 | } |
||
| 36 | |||
| 37 | if ($returnValue) { |
||
| 38 | $outcomes[] = new ReturnOutcome( |
||
| 39 | is_scalar($returnValue) ? @(string)$returnValue : '', |
||
| 40 | gettype($returnValue), |
||
| 41 | is_object($returnValue) ? get_class($returnValue) : '' |
||
| 42 | ); |
||
| 43 | } |
||
| 44 | } catch (\Exception $e) { |
||
| 45 | $outcomes[] = new ExceptionOutcome( |
||
| 46 | get_class($e), |
||
| 47 | $e->getMessage(), |
||
| 48 | $e->getCode() |
||
| 49 | ); |
||
| 50 | } |
||
| 51 | |||
| 52 | if ($output = ob_get_clean()) { |
||
| 53 | $outcomes[] = new OutputOutcome($output); |
||
| 54 | } |
||
| 55 | |||
| 56 | return $outcomes; |
||
| 57 | } |
||
| 59 |