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

ChunkStream   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

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
ccs 13
cts 13
cp 1
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 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