Row   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 100
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 4

Importance

Changes 0
Metric Value
dl 0
loc 100
rs 10
c 0
b 0
f 0
wmc 8
lcom 2
cbo 4

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A setGrid() 0 6 1
A getGrid() 0 4 1
A addCell() 0 6 1
A getIterator() 0 4 1
A get() 0 4 1
A raw() 0 4 1
A getValue() 0 4 1
1
<?php
2
3
namespace Boduch\Grid;
4
5
use Symfony\Component\HttpFoundation\ParameterBag;
6
7
/**
8
 * @property string $class
9
 * @property string $style
10
 */
11
class Row implements \IteratorAggregate
12
{
13
    use AttributesTrait;
14
15
    /**
16
     * @var Grid
17
     */
18
    protected $grid;
19
20
    /**
21
     * @var mixed|null
22
     */
23
    protected $raw;
24
25
    /**
26
     * @var CellInterface[]
27
     */
28
    protected $cells = [];
29
30
    /**
31
     * @param mixed|null $raw
32
     */
33
    public function __construct($raw = null)
34
    {
35
        $this->attributes = new ParameterBag();
36
        $this->raw = $raw;
37
    }
38
39
    /**
40
     * Grid can be accessed from helper functions.
41
     *
42
     * @param Grid $grid
43
     * @return $this
44
     */
45
    public function setGrid($grid)
46
    {
47
        $this->grid = $grid;
48
49
        return $this;
50
    }
51
52
    /**
53
     * @return Grid
54
     */
55
    public function getGrid()
56
    {
57
        return $this->grid;
58
    }
59
60
    /**
61
     * @param CellInterface $cell
62
     * @return $this
63
     */
64
    public function addCell(CellInterface $cell)
65
    {
66
        $this->cells[$cell->getColumn()->getName()] = $cell;
67
68
        return $this;
69
    }
70
71
    /**
72
     * @see IteratorAggregate::getIterator()
73
     */
74
    public function getIterator()
75
    {
76
        return new \ArrayIterator($this->cells);
77
    }
78
79
    /**
80
     * Get cell object by name.
81
     * @param string $name  Column name
82
     * @return CellInterface|null
83
     */
84
    public function get($name)
85
    {
86
        return $this->cells[$name] ?? null;
87
    }
88
89
    /**
90
     * Get raw row data.
91
     *
92
     * @param string $name
93
     * @return mixed|null
94
     */
95
    public function raw($name)
96
    {
97
        return $this->raw[$name] ?? null;
98
    }
99
100
    /**
101
     * Get cell value.
102
     *
103
     * @param string $name  Column name
104
     * @return mixed
105
     */
106
    public function getValue($name)
107
    {
108
        return $this->cells[$name]->getValue();
109
    }
110
}
111