Completed
Pull Request — master (#41)
by Nicolas
07:53
created

ChunkMetadata   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 0
dl 0
loc 53
ccs 24
cts 24
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A buildFromHeaders() 0 14 3
A playhead() 0 4 1
A offset() 0 4 1
A size() 0 4 1
A toHeaders() 0 8 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