| Conditions | 7 |
| Paths | 8 |
| Total Lines | 29 |
| Code Lines | 15 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 18 |
| CRAP Score | 7 |
| Changes | 0 | ||
| 1 | <?php |
||
| 11 | 2 | public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next) |
|
| 12 | { |
||
| 13 | /** @var ResponseInterface $response */ |
||
| 14 | 2 | $response = $next($request); |
|
| 15 | 2 | $body = $response->getBody(); |
|
| 16 | |||
| 17 | 2 | if ($body->isSeekable()) { |
|
| 18 | 1 | $body->rewind(); |
|
| 19 | 1 | } |
|
| 20 | |||
| 21 | 2 | if (!$body->isSeekable() || $body->tell() !== 0) { |
|
| 22 | 1 | $content = $this->changeCloudToButt($body); |
|
| 23 | |||
| 24 | 1 | return $response->withBody(stream_for($content)); |
|
| 25 | } |
||
| 26 | |||
| 27 | 1 | $newBody = stream_for(null); |
|
| 28 | |||
| 29 | 1 | while (!$body->eof()) { |
|
| 30 | 1 | $content = $body->read(4096); |
|
| 31 | 1 | while (!$body->eof() && substr($content, -1) !== ' ') { |
|
| 32 | 1 | $content .= $body->read(1); |
|
| 33 | 1 | } |
|
| 34 | |||
| 35 | 1 | $newBody->write($this->changeCloudToButt($content)); |
|
| 36 | 1 | } |
|
| 37 | |||
| 38 | 1 | return $response->withBody($newBody); |
|
| 39 | } |
||
| 40 | |||
| 46 |