Completed
Push — master ( a37643...7e1714 )
by Adam
03:13
created

Rows::offsetGet()   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 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Boduch\Grid;
4
5
class Rows implements \IteratorAggregate, \Countable, \ArrayAccess
6
{
7
    /**
8
     * @var Row[]
9
     */
10
    protected $rows = [];
11
12
    /**
13
     * @param array $rows
14
     */
15
    public function __construct(array $rows = [])
16
    {
17
        $this->rows = $rows;
18
    }
19
20
    /**
21
     * @see IteratorAggregate::getIterator()
22
     */
23
    public function getIterator()
24
    {
25
        return new \ArrayIterator($this->rows);
26
    }
27
28
    /**
29
     * Add row
30
     *
31
     * @param Row $row
32
     * @return Rows
33
     */
34
    public function addRow(Row $row)
35
    {
36
        $this->rows[] = $row;
37
38
        return $this;
39
    }
40
41
    /**
42
     * @see Countable::count()
43
     */
44
    public function count()
45
    {
46
        return count($this->rows);
47
    }
48
49
    /**
50
     * Returns the iterator as an array
51
     *
52
     * @return array
53
     */
54
    public function toArray()
55
    {
56
        return iterator_to_array($this->getIterator(), true);
57
    }
58
59
    /**
60
     * @param int $offset
61
     * @return bool
62
     */
63
    public function offsetExists($offset)
64
    {
65
        return isset($this->rows[$offset]);
66
    }
67
68
    /**
69
     * @param int $offset
70
     * @return Row|mixed|null
71
     */
72
    public function offsetGet($offset)
73
    {
74
        return $this->rows[$offset] ?? null;
75
    }
76
77
    /**
78
     * @param int $offset
79
     * @param Row $value
80
     */
81
    public function offsetSet($offset, $value)
82
    {
83
        throw new \InvalidArgumentException('offsetSet() currently not implemented.');
84
    }
85
86
    /**
87
     * @param int $offset
88
     */
89
    public function offsetUnset($offset)
90
    {
91
        throw new \InvalidArgumentException('offsetUnset() currently not implemented.');
92
    }
93
}
94