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

StaticBufferCollection::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 6
rs 9.4285
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