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

TableRow   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 98
Duplicated Lines 8.16 %

Coupling/Cohesion

Components 2
Dependencies 3

Test Coverage

Coverage 53.56%

Importance

Changes 0
Metric Value
dl 8
loc 98
rs 10
c 0
b 0
f 0
ccs 15
cts 28
cp 0.5356
wmc 14
lcom 2
cbo 3

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getTable() 0 4 1
A setTable() 0 10 3
A getCells() 0 4 1
A addCell() 0 10 2
A removeCell() 0 11 3
A getCell() 0 4 2
A insertCells() 8 8 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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