| Conditions | 4 | 
| Paths | 5 | 
| Total Lines | 22 | 
| Code Lines | 13 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 0 | ||
| 1 | <?php  | 
            ||
| 29 | public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next)  | 
            ||
| 30 |     { | 
            ||
| 31 |         if (!self::hasAttribute($request, EncodingNegotiator::KEY)) { | 
            ||
| 32 |             throw new RuntimeException('Gzip middleware needs EncodingNegotiator executed before'); | 
            ||
| 33 | }  | 
            ||
| 34 | |||
| 35 | $response = $next($request, $response);  | 
            ||
| 36 | |||
| 37 | $resolver = $this->resolver ?: new Transformers\Encoder();  | 
            ||
| 38 | $encoding = EncodingNegotiator::getEncoding($request);  | 
            ||
| 39 | $transformer = $resolver->resolve($encoding);  | 
            ||
| 40 | |||
| 41 |         if ($transformer) { | 
            ||
| 42 | $body = $response->getBody();  | 
            ||
| 43 | |||
| 44 | return $response  | 
            ||
| 45 |                 ->withHeader('Content-Encoding', $encoding) | 
            ||
| 46 | ->withBody($transformer($body, self::createStream($body)));  | 
            ||
| 47 | }  | 
            ||
| 48 | |||
| 49 | return $response;  | 
            ||
| 50 | }  | 
            ||
| 51 | }  | 
            ||
| 52 |