Completed
Pull Request — master (#5)
by Márk
02:06
created

ChunkStream::getReadFilter()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 9.4286
cc 2
eloc 4
nc 2
nop 0
crap 2
1
<?php
2
3
namespace Http\Message\Encoding;
4
5
/**
6
 * Transform a regular stream into a chunked one
7
 *
8
 * @author Joel Wurtz <[email protected]>
9
 */
10
class ChunkStream extends FilteredStream
11
{
12
    /**
13
     * {@inheritdoc}
14
     */
15 4
    public function getReadFilter()
16
    {
17 4
        if (!array_key_exists('chunk', stream_get_filters())) {
18 4
            stream_filter_register('chunk', 'Http\Message\Encoding\Filter\Chunk');
19 4
        }
20
21 4
        return 'chunk';
22
    }
23
24
    /**
25
     * {@inheritdoc}
26
     */
27 4
    public function getWriteFilter()
28
    {
29 4
        return 'dechunk';
30
    }
31
32 2
    protected function fill()
33
    {
34 2
        parent::fill();
35
36 2
        if ($this->stream->eof()) {
37 2
            $this->buffer .= "0\r\n\r\n";
38 2
        }
39 2
    }
40
}
41