Completed
Pull Request — master (#5)
by Márk
07:08
created

ChunkStream::fill()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 8
ccs 0
cts 7
cp 0
rs 9.4286
cc 2
eloc 4
nc 2
nop 0
crap 6
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
    public function getReadFilter()
16
    {
17
        if (!array_key_exists('chunk', stream_get_filters())) {
18
            stream_filter_register('chunk', 'Http\Message\Encoding\Filter\Chunk');
19
        }
20
21
        return 'chunk';
22
    }
23
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function getWriteFilter()
28
    {
29
        return 'dechunk';
30
    }
31
32
    protected function fill()
33
    {
34
        parent::fill();
35
36
        if ($this->stream->eof()) {
37
            $this->buffer .= "0\r\n\r\n";
38
        }
39
    }
40
}
41