Passed
Pull Request — master (#31)
by Josh
03:43
created

TableRow::setTable()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 10
ccs 0
cts 6
cp 0
rs 9.4285
cc 2
eloc 5
nc 2
nop 1
crap 6
1
<?php
2
3
namespace Caxy\HtmlDiff\Table;
4
5
class TableRow extends AbstractTableElement
6
{
7
    /**
8
     * @var Table
9
     */
10
    protected $table;
11
12
    /**
13
     * @var array
14
     */
15
    protected $cells = array();
16
    
17
    public function getTable()
18
    {
19
        return $this->table;
20
    }
21
22
    public function setTable(Table $table = null)
23
    {
24
        $this->table = $table;
25
26
        if (!in_array($this, $table->getRows())) {
27
            $table->addRow($this);
0 ignored issues
show
Bug introduced by
It seems like $table is not always an object, but can also be of type null. Maybe add an additional type check?

If a variable is not always an object, we recommend to add an additional type check to ensure your method call is safe:

function someFunction(A $objectMaybe = null)
{
    if ($objectMaybe instanceof A) {
        $objectMaybe->doSomething();
    }
}
Loading history...
28
        }
29
30
        return $this;
31
    }
32
33
    public function getCells()
34
    {
35
        return $this->cells;
36
    }
37
38
    public function addCell(TableCell $cell)
39
    {
40
        $this->cells[] = $cell;
41
42
        if (!$cell->getRow()) {
43
            $cell->setRow($this);
44
        }
45
46
        return $this;
47
    }
48
49
    public function removeCell(TableCell $cell)
50
    {
51
        $key = array_search($cell, $this->cells, true);
52
53
        if ($key !== false) {
54
            unset($this->cells[$key]);
55
            if ($cell->getRow()) {
56
                $cell->setRow(null);
57
            }
58
        }
59
    }
60
61
    /**
62
     * @param $index
63
     *
64
     * @return TableCell|null
65
     */
66
    public function getCell($index)
67
    {
68
        return isset($this->cells[$index]) ? $this->cells[$index] : null;
69
    }
70
71
    /**
72
     * @param array $cells
73
     * @param null  $position
74
     */
75 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...
76
    {
77
        if ($position === null) {
78
            $this->cells = array_merge($this->cells, $cells);
79
        } else {
80
            array_splice($this->cells, $position, 0, $cells);
81
        }
82
    }
83
}
84