Completed
Pull Request — master (#348)
by thomas
70:36
created

AbstractCollectionMutator::offsetUnset()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 8
rs 9.4285
1
<?php
2
3
namespace BitWasp\Bitcoin\Transaction\Mutator;
4
5
abstract class AbstractCollectionMutator implements \Iterator, \ArrayAccess, \Countable
6
{
7
    /**
8
     * @var \SplFixedArray
9
     */
10
    protected $set;
11
12
    /**
13
     * @return array
14
     */
15
    public function all()
16
    {
17
        return $this->set->toArray();
18
    }
19
20
    /**
21
     * @return bool
22
     */
23
    public function isNull()
24
    {
25
        return count($this->set) === 0;
26
    }
27
28
    /**
29
     * @return int
30
     */
31
    public function count()
32
    {
33
        return $this->set->count();
34
    }
35
36
    /**
37
     *
38
     */
39
    public function rewind()
40
    {
41
        $this->set->rewind();
42
    }
43
44
    /**
45
     * @return mixed
46
     */
47
    public function current()
48
    {
49
        return $this->set->current();
50
    }
51
52
    /**
53
     * @return int
54
     */
55
    public function key()
56
    {
57
        return $this->set->key();
58
    }
59
60
    /**
61
     *
62
     */
63
    public function next()
64
    {
65
        $this->set->next();
66
    }
67
68
    /**
69
     * @return bool
70
     */
71
    public function valid()
72
    {
73
        return $this->set->valid();
74
    }
75
76
    /**
77
     * @param int $offset
78
     * @return bool
79
     */
80
    public function offsetExists($offset)
81
    {
82
        return $this->set->offsetExists($offset);
83
    }
84
85
    /**
86
     * @param int $offset
87
     */
88
    public function offsetUnset($offset)
89
    {
90
        if (!$this->offsetExists($offset)) {
91
            throw new \InvalidArgumentException('Offset does not exist');
92
        }
93
94
        $this->set->offsetUnset($offset);
95
    }
96
97
    /**
98
     * @param int $offset
99
     * @return mixed
100
     */
101
    public function offsetGet($offset)
102
    {
103
        if (!$this->set->offsetExists($offset)) {
104
            throw new \OutOfRangeException('Nothing found at this offset');
105
        }
106
        return $this->set->offsetGet($offset);
107
    }
108
109
    /**
110
     * @param int $offset
111
     * @param mixed $value
112
     */
113
    public function offsetSet($offset, $value)
114
    {
115
        $this->set->offsetSet($offset, $value);
116
    }
117
}
118