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

ChunkStream   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 5
c 1
b 0
f 1
lcom 1
cbo 2
dl 0
loc 31
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getReadFilter() 0 8 2
A getWriteFilter() 0 4 1
A fill() 0 8 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
    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