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 |
||
34 | abstract class AbstractTableSection extends AbstractElement |
||
35 | { |
||
36 | /** |
||
37 | * |
||
38 | * @var TableRow[] |
||
39 | */ |
||
40 | private $rows = array(); |
||
41 | |||
42 | /** |
||
43 | * A reference to the table where the section is attached to |
||
44 | * |
||
45 | * @var Table |
||
46 | */ |
||
47 | private $table; |
||
48 | |||
49 | function __construct(Table $table = null) |
||
53 | |||
54 | /** |
||
55 | * |
||
56 | * @return \PHPHealth\CDA\Elements\TableRow |
||
57 | */ |
||
58 | public function createRow() |
||
66 | |||
67 | /** |
||
68 | * |
||
69 | * @param \PHPHealth\CDA\Elements\TableRow $row |
||
70 | * @return $this |
||
71 | */ |
||
72 | public function addRow(TableRow $row) |
||
78 | /** |
||
79 | * |
||
80 | * @return TableRow[] |
||
81 | */ |
||
82 | function getRows(): array |
||
86 | |||
87 | function setRows(array $rows) |
||
92 | |||
93 | /** |
||
94 | * |
||
95 | * @return \PHPHealth\CDA\Elements\Table |
||
96 | */ |
||
97 | function getTable(): Table |
||
101 | |||
102 | /** |
||
103 | * |
||
104 | * @param \PHPHealth\CDA\Elements\Table $table |
||
105 | * @return $this |
||
106 | */ |
||
107 | function setTable(Table $table) |
||
113 | |||
114 | /** |
||
115 | * |
||
116 | * @return boolean |
||
117 | */ |
||
118 | public function isEmpty() |
||
122 | |||
123 | |||
124 | View Code Duplication | public function toDOMElement(\DOMDocument $doc): \DOMElement |
|
134 | |||
135 | } |
||
136 |
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.