Collection::getIterator()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace JimmyOak\Collection;
4
5
class Collection implements \ArrayAccess, \Countable, \IteratorAggregate
6
{
7
    /** @var array */
8
    protected $collection = [];
9
10
    public function offsetExists($offset)
11
    {
12
        return isset($this->collection[$offset]);
13
    }
14
15
    public function offsetGet($offset)
16
    {
17
        return $this->collection[$offset];
18
    }
19
20
    public function offsetSet($offset, $value)
21
    {
22
        if ($offset === null) {
23
            $this->collection[] = $value;
24
        } else {
25
            $this->collection[$offset] = $value;
26
        }
27
    }
28
29
    public function offsetUnset($offset)
30
    {
31
        unset($this->collection[$offset]);
32
    }
33
34
    public function count()
35
    {
36
        return count($this->collection);
37
    }
38
39
    public function getIterator()
40
    {
41
        return new \ArrayIterator($this->collection);
42
    }
43
}
44