Completed
Push — master ( b4333d...f02c0d )
by thomas
14s
created

StaticBufferCollection   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 71.43%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
dl 0
loc 60
ccs 10
cts 14
cp 0.7143
rs 10
c 2
b 0
f 1
wmc 6
lcom 1
cbo 1

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A bottom() 0 4 1
A top() 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 81
        array_map(function (BufferInterface $data) {
26 47
            $this->set[] = $data;
27 81
        }, $sigValues);
28 81
    }
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 top()
42
    {
43
        return parent::top();
44
    }
45
46
    /**
47
     * @return BufferInterface
48
     */
49 42
    public function current()
50
    {
51 42
        return $this->set[$this->position];
52
    }
53
54
    /**
55
     * @param int $offset
56
     * @return BufferInterface
57
     */
58 45
    public function offsetGet($offset)
59
    {
60 45
        if (!array_key_exists($offset, $this->set)) {
61 6
            throw new \OutOfRangeException('No offset found');
62
        }
63
64 39
        return $this->set[$offset];
65
    }
66
}
67