Passed
Pull Request — master (#41)
by Nicolas
07:46 queued 33s
created

ChunkMetadata::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 3
crap 1
1
<?php
2
3
namespace Puzzle\AMQP\Messages\Chunks;
4
5
final class ChunkMetadata
6
{
7
    private
8
        $playhead,
9
        $offset,
10
        $size;
11
12 4
    public function __construct($playhead, $offset, $size)
13
    {
14 4
        $this->playhead = $playhead;
15 4
        $this->offset = $offset;
16 4
        $this->size = $size;
17 4
    }
18
19 2
    public static function buildFromHeaders(array $headers)
20
    {
21 2
        $requiredKeys = ['playhead', 'offset', 'size'];
22
23 2
        foreach($requiredKeys as $key)
24
        {
25 2
            if(! isset($headers[$key]))
26 2
            {
27 1
                throw new \InvalidArgumentException("Missing $key in chunk metadata");
28
            }
29 1
        }
30
31 1
        return new self($headers['playhead'], $headers['offset'], $headers['size']);
32
    }
33
34 1
    public function playhead()
35
    {
36 1
        return $this->playhead;
37
    }
38
39 1
    public function offset()
40
    {
41 1
        return $this->offset;
42
    }
43
44 4
    public function size()
45
    {
46 4
        return $this->size;
47
    }
48
49 2
    public function toHeaders()
50
    {
51
        return [
52 2
            'offset' => $this->offset,
53 2
            'playhead' => $this->playhead,
54 2
            'size' => $this->size,
55 2
        ];
56
    }
57
}
58