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 |
||
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() |
|
27 | |||
28 | /** |
||
29 | * @param Table|null $table |
||
30 | * |
||
31 | * @return $this |
||
32 | */ |
||
33 | 1 | public function setTable(Table $table = null) |
|
43 | |||
44 | /** |
||
45 | * @return TableCell[] |
||
46 | */ |
||
47 | 1 | public function getCells() |
|
51 | |||
52 | /** |
||
53 | * @param TableCell $cell |
||
54 | * |
||
55 | * @return $this |
||
56 | */ |
||
57 | 1 | public function addCell(TableCell $cell) |
|
67 | |||
68 | /** |
||
69 | * @param TableCell $cell |
||
70 | */ |
||
71 | public function removeCell(TableCell $cell) |
||
82 | |||
83 | /** |
||
84 | * @param int $index |
||
85 | * |
||
86 | * @return TableCell|null |
||
87 | */ |
||
88 | 1 | public function getCell($index) |
|
92 | |||
93 | /** |
||
94 | * @param TableCell[] $cells |
||
95 | * @param null|int $position |
||
96 | */ |
||
97 | View Code Duplication | public function insertCells($cells, $position = null) |
|
105 | } |
||
106 |
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.