Completed
Pull Request — master (#591)
by thomas
30:58
created

StaticBufferCollection   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 84.62%

Importance

Changes 0
Metric Value
dl 0
loc 58
ccs 11
cts 13
cp 0.8462
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 1

5 Methods

Rating   Name   Duplication   Size   Complexity  
A top() 0 4 1
A current() 0 4 1
A offsetGet() 0 8 2
A bottom() 0 4 1
A __construct() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BitWasp\Bitcoin\Collection;
6
7
use BitWasp\Buffertools\BufferInterface;
8
9
class StaticBufferCollection extends StaticCollection
10
{
11
    /**
12
     * @var BufferInterface[]
13
     */
14
    protected $set = [];
15
16
    /**
17
     * @var int
18
     */
19
    protected $position = 0;
20
21
    /**
22
     * StaticBufferCollection constructor.
23
     * @param BufferInterface[] $values
24
     */
25 214
    public function __construct(BufferInterface... $values)
26
    {
27 214
        $this->set = $values;
0 ignored issues
show
Documentation Bug introduced by
It seems like $values of type array<integer,array<inte...ools\BufferInterface>>> is incompatible with the declared type array<integer,object<Bit...tools\BufferInterface>> of property $set.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
28 214
    }
29
30
    /**
31
     * @return BufferInterface
32
     */
33 17
    public function bottom(): BufferInterface
34
    {
35 17
        return parent::bottom();
36
    }
37
38
    /**
39
     * @return BufferInterface
40
     */
41
    public function top(): BufferInterface
42
    {
43
        return parent::top();
44
    }
45
46
    /**
47
     * @return BufferInterface
48
     */
49 132
    public function current(): BufferInterface
50
    {
51 132
        return $this->set[$this->position];
52
    }
53
54
    /**
55
     * @param int $offset
56
     * @return BufferInterface
57
     */
58 144
    public function offsetGet($offset)
59
    {
60 144
        if (!array_key_exists($offset, $this->set)) {
61 2
            throw new \OutOfRangeException('No offset found');
62
        }
63
64 142
        return $this->set[$offset];
65
    }
66
}
67