Completed
Pull Request — master (#524)
by thomas
40:24 queued 38:13
created

PathTrace   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 112
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 63.33%

Importance

Changes 0
Metric Value
dl 0
loc 112
ccs 19
cts 30
cp 0.6333
rs 10
c 0
b 0
f 0
wmc 14
lcom 1
cbo 0

11 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 3
A count() 0 4 1
A rewind() 0 4 1
A current() 0 4 1
A key() 0 4 1
A next() 0 4 1
A valid() 0 4 1
A offsetSet() 0 4 1
A offsetExists() 0 4 1
A offsetUnset() 0 4 1
A offsetGet() 0 4 2
1
<?php
2
3
namespace BitWasp\Bitcoin\Script\Path;
4
5
class PathTrace implements \ArrayAccess, \Iterator, \Countable
6
{
7
    /**
8
     * @var OperationContainer[]
9
     */
10
    private $container;
11
12
    /**
13
     * @var int
14
     */
15
    private $position = 0;
16
17
    /**
18
     * @var int
19
     */
20
    private $count = 0;
21
22
    /**
23
     * PathTrace constructor.
24
     * @param OperationContainer[] $opsLists
25
     */
26 126
    public function __construct(array $opsLists)
27
    {
28 126
        foreach ($opsLists as $opList) {
29 126
            if (!($opList instanceof OperationContainer)) {
30 126
                throw new \InvalidArgumentException("Invalid argument: Array of OperationContainer required");
31
            }
32
        }
33 126
        $this->container = $opsLists;
34 126
        $this->count = count($opsLists);
35 126
    }
36
37
    /**
38
     * @return int
39
     */
40
    public function count()
41
    {
42
        return $this->count;
43
    }
44
45
    /**
46
     *
47
     */
48 126
    public function rewind()
49
    {
50 126
        $this->position = 0;
51 126
    }
52
53
    /**
54
     * @return OperationContainer
55
     */
56 126
    public function current()
57
    {
58 126
        return $this->container[$this->position];
59
    }
60
61
    /**
62
     * @return int
63
     */
64 108
    public function key()
65
    {
66 108
        return $this->position;
67
    }
68
69 116
    public function next()
70
    {
71 116
        ++$this->position;
72 116
    }
73
74
    /**
75
     * @return bool
76
     */
77 126
    public function valid()
78
    {
79 126
        return isset($this->container[$this->position]);
80
    }
81
82
    /**
83
     * @param int $offset
84
     * @param OperationContainer $value
85
     */
86
    public function offsetSet($offset, $value)
87
    {
88
        throw new \RuntimeException("Not implemented");
89
    }
90
91
    /**
92
     * @param int $offset
93
     * @return bool
94
     */
95
    public function offsetExists($offset)
96
    {
97
        return isset($this->container[$offset]);
98
    }
99
100
    /**
101
     * @param int $offset
102
     */
103
    public function offsetUnset($offset)
104
    {
105
        unset($this->container[$offset]);
106
    }
107
108
    /**
109
     * @param int $offset
110
     * @return OperationContainer|null
111
     */
112
    public function offsetGet($offset)
113
    {
114
        return isset($this->container[$offset]) ? $this->container[$offset] : null;
115
    }
116
}
117