Row   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 93
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 75%

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 3
dl 0
loc 93
ccs 21
cts 28
cp 0.75
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A getCells() 0 4 1
A getActions() 0 4 1
A getEntity() 0 4 1
A setEntity() 0 12 3
A __toString() 0 18 3
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Foo\Grid\Row;
6
7
use Foo\Grid\Cell\Cell;
8
use Foo\Grid\Collection\Actions;
9
use Foo\Grid\Collection\Cells;
10
use Foo\Grid\Component\Component;
11
use Opulence\Orm\IEntity;
12
13
class Row extends Component implements IRow
14
{
15
    const TAG = 'tr';
16
17
    /** @var Cells */
18
    protected $cells;
19
20
    /** @var Actions */
21
    protected $actions;
22
23
    /** @var IEntity */
24
    protected $entity;
25
26
    /**
27
     * Row constructor.
28
     *
29
     * @param Cells        $cells
30
     * @param Actions|null $actions
31
     * @param array        $attributes
32
     * @param string       $tag
33
     */
34 7
    public function __construct(Cells $cells, Actions $actions = null, array $attributes = [], string $tag = self::TAG)
35
    {
36 7
        $this->cells   = $cells;
37 7
        $this->actions = $actions;
38
39 7
        parent::__construct('', $tag, $attributes);
40
41 7
        $this->appendToAttribute(Component::ATTRIBUTE_CLASS, $tag);
42 7
    }
43
44
    /**
45
     * @return string
46
     */
47
    public function getCells(): Cells
48
    {
49
        return $this->cells;
50
    }
51
52
    /**
53
     * @return Actions
54
     */
55
    public function getActions(): Actions
56
    {
57
        return $this->actions;
58
    }
59
60
    /**
61
     * @return IEntity
62
     */
63
    public function getEntity(): IEntity
64
    {
65
        return $this->entity;
66
    }
67
68
    /**
69
     * @param IEntity $entity
70
     */
71 1
    public function setEntity(IEntity $entity)
72
    {
73 1
        $this->entity = $entity;
74
75 1
        if (null === $this->actions) {
76
            return;
77
        }
78
79 1
        foreach ($this->actions as $action) {
80 1
            $action->setEntity($entity);
81
        }
82 1
    }
83
84
    /**
85
     * @return string
86
     */
87 2
    public function __toString(): string
88
    {
89 2
        $this->content = (string)$this->cells;
90
91 2
        if ($this->actions) {
92 2
            $cell = new Cell((string)$this->actions, 'actions');
93
94 2
            if ($this->translator) {
95 1
                $cell->setTranslator($this->translator);
96
            }
97
98 2
            $this->content .= $cell;
99
        }
100
101 2
        $return = parent::__toString();
102
103 2
        return $return;
104
    }
105
}
106