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 |
||
38 | class TableRow extends AbstractElement |
||
39 | { |
||
40 | /** |
||
41 | * |
||
42 | * @var TableCell[] |
||
43 | */ |
||
44 | private $cells; |
||
45 | |||
46 | /** |
||
47 | * a reference to the section this row is attached to |
||
48 | * |
||
49 | * @var AbstractTableSection |
||
50 | */ |
||
51 | private $section; |
||
52 | |||
53 | /** |
||
54 | * |
||
55 | * @var Reference |
||
56 | */ |
||
57 | private $reference; |
||
58 | |||
59 | function __construct(AbstractTableSection $section = null) |
||
63 | |||
64 | /** |
||
65 | * |
||
66 | * @param string $content |
||
67 | * @return TableCell |
||
68 | */ |
||
69 | function createCell($content) |
||
80 | |||
81 | /** |
||
82 | * |
||
83 | * @param TableCell $cell |
||
84 | * @return $this |
||
85 | */ |
||
86 | public function addCell(TableCell $cell) |
||
94 | |||
95 | /** |
||
96 | * |
||
97 | * @return TableCell[] |
||
98 | */ |
||
99 | function getCells(): array |
||
103 | |||
104 | function getSection(): AbstractTableSection |
||
108 | |||
109 | function setCells(array $cells) |
||
114 | |||
115 | function setSection(AbstractTableSection $section) |
||
120 | |||
121 | /** |
||
122 | * |
||
123 | * @return Reference |
||
124 | */ |
||
125 | function getReference() |
||
129 | |||
130 | /** |
||
131 | * |
||
132 | * @param ReferenceType $reference |
||
133 | * @return $this |
||
134 | */ |
||
135 | function setReference(ReferenceType $reference) |
||
141 | |||
142 | |||
143 | /** |
||
144 | * |
||
145 | * @return boolean |
||
146 | */ |
||
147 | public function isEmpty() |
||
151 | |||
152 | |||
153 | protected function getElementTag(): string |
||
157 | |||
158 | View Code Duplication | public function toDOMElement(\DOMDocument $doc): \DOMElement |
|
172 | } |
||
173 |
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.