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

StaticBufferCollection   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 85.71%

Importance

Changes 0
Metric Value
dl 0
loc 60
ccs 12
cts 14
cp 0.8571
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 1

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A top() 0 4 1
A current() 0 4 1
A offsetGet() 0 8 2
A bottom() 0 4 1
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