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

Rows   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 89
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 89
rs 10
c 0
b 0
f 0
wmc 9
lcom 1
cbo 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getIterator() 0 4 1
A addRow() 0 6 1
A count() 0 4 1
A toArray() 0 4 1
A offsetExists() 0 4 1
A offsetGet() 0 4 1
A offsetSet() 0 4 1
A offsetUnset() 0 4 1
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