Completed
Pull Request — master (#446)
by thomas
105:00 queued 101:56
created

StaticBufferCollection::offsetGet()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 8
ccs 4
cts 4
cp 1
crap 2
rs 9.4285
c 0
b 0
f 0
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 125
        array_map(function (BufferInterface $data) {
26 83
            $this->set[] = $data;
27 125
        }, $sigValues);
28 125
    }
29
30
    /**
31
     * @return BufferInterface
32
     */
33 2
    public function bottom()
34
    {
35 2
        return parent::bottom();
36
    }
37
38
    /**
39
     * @return BufferInterface
40
     */
41
    public function top()
42
    {
43
        return parent::top();
44
    }
45
46
    /**
47
     * @return BufferInterface
48
     */
49 76
    public function current()
50
    {
51 76
        return $this->set[$this->position];
52
    }
53
54
    /**
55
     * @param int $offset
56
     * @return BufferInterface
57
     */
58 89
    public function offsetGet($offset)
59
    {
60 89
        if (!array_key_exists($offset, $this->set)) {
61 4
            throw new \OutOfRangeException('No offset found');
62
        }
63
64 85
        return $this->set[$offset];
65
    }
66
}
67