Completed
Pull Request — master (#524)
by thomas
71:45
created

PathTrace::valid()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
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
    public function __construct(array $opsLists)
27
    {
28
        foreach ($opsLists as $opList) {
29
            if (!($opList instanceof OperationContainer)) {
30
                throw new \InvalidArgumentException("Invalid argument: Array of OperationContainer required");
31
            }
32
        }
33
        $this->container = $opsLists;
34
        $this->count = count($opsLists);
35
    }
36
37
    /**
38
     * @return int
39
     */
40
    public function count()
41
    {
42
        return $this->count;
43
    }
44
45
    /**
46
     *
47
     */
48
    public function rewind()
49
    {
50
        $this->position = 0;
51
    }
52
53
    /**
54
     * @return OperationContainer
55
     */
56
    public function current()
57
    {
58
        return $this->container[$this->position];
59
    }
60
61
    /**
62
     * @return int
63
     */
64
    public function key()
65
    {
66
        return $this->position;
67
    }
68
69
    public function next()
70
    {
71
        ++$this->position;
72
    }
73
74
    /**
75
     * @return bool
76
     */
77
    public function valid()
78
    {
79
        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