Completed
Pull Request — master (#348)
by thomas
70:36
created

StaticBufferCollection   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A bottom() 0 4 1
A current() 0 4 1
A offsetGet() 0 8 2
1
<?php
2
3
namespace BitWasp\Bitcoin\Collection;
4
5
use BitWasp\Buffertools\BufferInterface;
6
7
class StaticBufferCollection extends StaticCollection
8
{
9
    /**
10
     * @var BufferInterface[]
11
     */
12
    protected $set = [];
13
14
    /**
15
     * @var int
16
     */
17
    protected $position = 0;
18
19
    /**
20
     * StaticBufferCollection constructor.
21
     * @param BufferInterface[] $sigValues
22
     */
23
    public function __construct(array $sigValues)
24
    {
25
        array_map(function (BufferInterface $data) {
26
            $this->set[] = $data;
27
        }, $sigValues);
28
    }
29
30
    /**
31
     * @return BufferInterface
32
     */
33
    public function bottom()
34
    {
35
        return parent::bottom();
36
    }
37
38
    /**
39
     * @return BufferInterface
40
     */
41
    public function current()
42
    {
43
        return $this->set[$this->position];
44
    }
45
46
    /**
47
     * @param int $offset
48
     * @return BufferInterface
49
     */
50
    public function offsetGet($offset)
51
    {
52
        if (!array_key_exists($offset, $this->set)) {
53
            throw new \OutOfRangeException('No offset found');
54
        }
55
56
        return $this->set[$offset];
57
    }
58
}
59