| Conditions | 4 |
| Paths | 4 |
| Total Lines | 27 |
| Code Lines | 18 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 12 |
| CRAP Score | 4.5923 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 24 | 3 | public function sendResponse(string $target): Response |
|
| 25 | { |
||
| 26 | 3 | if (!\file_exists($target)) { |
|
| 27 | throw new IOException( |
||
| 28 | \sprintf("File `%s` does not exist.", $target) |
||
| 29 | ); |
||
| 30 | } |
||
| 31 | 3 | $level = \ob_get_level(); |
|
| 32 | 3 | \ob_start(); |
|
| 33 | 3 | \ob_implicit_flush(0); |
|
| 34 | try { |
||
| 35 | 3 | include $target; |
|
| 36 | } catch (Throwable $e) { |
||
| 37 | while (\ob_get_level() > $level) { |
||
| 38 | \ob_end_clean(); |
||
| 39 | } |
||
| 40 | throw $e; |
||
| 41 | } |
||
| 42 | |||
| 43 | 3 | $content = \ob_get_clean(); |
|
| 44 | |||
| 45 | 3 | $stream = $this->response->getBody(); |
|
| 46 | 3 | $stream->rewind(); |
|
| 47 | 3 | $stream->write($content); |
|
| 48 | 3 | $this->response = $this->response->withBody($stream); |
|
| 49 | |||
| 50 | 3 | return $this->response; |
|
| 51 | } |
||
| 53 |