Passed
Push — master ( d304b3...db8bd2 )
by Sven
01:20 queued 11s
created

TableRow::setTable()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 3.072

Importance

Changes 0
Metric Value
cc 3
nc 2
nop 1
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
ccs 4
cts 5
cp 0.8
crap 3.072
1
<?php
2
3
namespace Caxy\HtmlDiff\Table;
4
5
/**
6
 * Class TableRow.
7
 */
8
class TableRow extends AbstractTableElement
9
{
10
    /**
11
     * @var Table
12
     */
13
    protected $table;
14
15
    /**
16
     * @var TableCell[]
17
     */
18
    protected $cells = array();
19
20
    /**
21
     * @return Table
22
     */
23 1
    public function getTable()
24
    {
25 1
        return $this->table;
26
    }
27
28
    /**
29
     * @param Table|null $table
30
     *
31
     * @return $this
32
     */
33 1
    public function setTable(Table $table = null)
34
    {
35 1
        $this->table = $table;
36
37 1
        if ($table && !in_array($this, $table->getRows())) {
38
            $table->addRow($this);
39
        }
40
41 1
        return $this;
42
    }
43
44
    /**
45
     * @return TableCell[]
46
     */
47 1
    public function getCells()
48
    {
49 1
        return $this->cells;
50
    }
51
52
    /**
53
     * @param TableCell $cell
54
     *
55
     * @return $this
56
     */
57 1
    public function addCell(TableCell $cell)
58
    {
59 1
        $this->cells[] = $cell;
60
61 1
        if (!$cell->getRow()) {
62 1
            $cell->setRow($this);
63
        }
64
65 1
        return $this;
66
    }
67
68
    /**
69
     * @param TableCell $cell
70
     */
71
    public function removeCell(TableCell $cell)
72
    {
73
        $key = array_search($cell, $this->cells, true);
74
75
        if ($key !== false) {
76
            unset($this->cells[$key]);
77
            if ($cell->getRow()) {
78
                $cell->setRow(null);
79
            }
80
        }
81
    }
82
83
    /**
84
     * @param int $index
85
     *
86
     * @return TableCell|null
87
     */
88 1
    public function getCell($index)
89
    {
90 1
        return isset($this->cells[$index]) ? $this->cells[$index] : null;
91
    }
92
93
    /**
94
     * @param TableCell[] $cells
95
     * @param null|int    $position
96
     */
97 View Code Duplication
    public function insertCells($cells, $position = null)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
98
    {
99
        if ($position === null) {
100
            $this->cells = array_merge($this->cells, $cells);
101
        } else {
102
            array_splice($this->cells, $position, 0, $cells);
103
        }
104
    }
105
}
106