Completed
Pull Request — master (#244)
by thomas
201:55 queued 131:14
created

MutableCollection::all()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
namespace BitWasp\Bitcoin\Collection;
4
5
abstract class MutableCollection implements CollectionInterface
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 94
    public function count()
32
    {
33 94
        return $this->set->count();
34 94
    }
35
36
    /**
37
     *
38
     */
39
    public function rewind()
40
    {
41
        $this->set->rewind();
42
    }
43
44
    /**
45
     * @return mixed
46
     */
47 12
    public function current()
48
    {
49 12
        return $this->set->current();
50
    }
51
52
    /**
53
     * @return int
54
     */
55 94
    public function key()
56
    {
57 94
        return $this->set->key();
58 94
    }
59
60
    /**
61
     *
62
     */
63 94
    public function next()
64
    {
65 94
        $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