Encoder::gzip()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
3
namespace Psr7Middlewares\Transformers;
4
5
use Psr\Http\Message\StreamInterface;
6
7
/**
8
 * Generic resolver to encode responses.
9
 */
10
class Encoder extends Resolver
11
{
12
    protected $transformers = [
13
        'gzip' => [__CLASS__, 'gzip'],
14
        'deflate' => [__CLASS__, 'deflate'],
15
    ];
16
17
    /**
18
     * Gzip minifier using gzencode().
19
     *
20
     * @param StreamInterface $input
21
     * @param StreamInterface $output
22
     *
23
     * @return ResponseInterface
24
     */
25
    public static function gzip(StreamInterface $input, StreamInterface $output)
26
    {
27
        $output->write(gzencode((string) $input));
28
29
        return $output;
30
    }
31
32
    /**
33
     * Gzip minifier using gzdeflate().
34
     *
35
     * @param StreamInterface $input
36
     * @param StreamInterface $output
37
     *
38
     * @return ResponseInterface
39
     */
40
    public static function deflate(StreamInterface $input, StreamInterface $output)
41
    {
42
        $output->write(gzdeflate((string) $input));
43
44
        return $output;
45
    }
46
}
47