We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
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 |
||
5 | trait Columns |
||
6 | { |
||
7 | // ------------ |
||
8 | // COLUMNS |
||
9 | // ------------ |
||
10 | |||
11 | /** |
||
12 | * Add a bunch of column names and their details to the CRUD object. |
||
13 | * |
||
14 | * @param [array or multi-dimensional array] |
||
15 | */ |
||
16 | public function setColumns($columns) |
||
48 | |||
49 | /** |
||
50 | * Add a column at the end of to the CRUD object's "columns" array. |
||
51 | * |
||
52 | * @param [string or array] |
||
53 | */ |
||
54 | public function addColumn($column) |
||
68 | |||
69 | /** |
||
70 | * Add multiple columns at the end of the CRUD object's "columns" array. |
||
71 | * |
||
72 | * @param [array of columns] |
||
73 | */ |
||
74 | public function addColumns($columns) |
||
82 | |||
83 | /** |
||
84 | * Moves the recently added column to 'before' the $target_col |
||
85 | * |
||
86 | * @param $target_col |
||
87 | */ |
||
88 | View Code Duplication | public function beforeColumn($target_col) { |
|
96 | |||
97 | /** |
||
98 | * Moves the recently added column to 'after' the $target_col |
||
99 | * |
||
100 | * @param $target |
||
101 | */ |
||
102 | View Code Duplication | public function afterColumn($target_col) { |
|
110 | |||
111 | /** |
||
112 | * Add the default column type to the given Column, inferring the type from the database column type. |
||
113 | * |
||
114 | * @param [column array] |
||
115 | */ |
||
116 | public function addDefaultTypeToColumn($column) |
||
126 | |||
127 | /** |
||
128 | * If a field or column array is missing the "label" attribute, an ugly error would be show. |
||
129 | * So we add the field Name as a label - it's better than nothing. |
||
130 | * |
||
131 | * @param [field or column] |
||
132 | */ |
||
133 | public function addDefaultLabel($array) |
||
143 | |||
144 | /** |
||
145 | * Remove multiple columns from the CRUD object using their names. |
||
146 | * |
||
147 | * @param [column array] |
||
148 | */ |
||
149 | public function removeColumns($columns) |
||
153 | |||
154 | /** |
||
155 | * Remove a column from the CRUD object using its name. |
||
156 | * |
||
157 | * @param [column array] |
||
158 | */ |
||
159 | public function removeColumn($column) |
||
163 | |||
164 | /** |
||
165 | * @param string $entity |
||
166 | */ |
||
167 | public function remove($entity, $fields) |
||
173 | |||
174 | /** |
||
175 | * Change attributes for multiple columns. |
||
176 | * |
||
177 | * @param [columns arrays] |
||
178 | * @param [attributes and values array] |
||
179 | */ |
||
180 | public function setColumnsDetails($columns, $attributes) |
||
184 | |||
185 | /** |
||
186 | * Change attributes for a certain column. |
||
187 | * |
||
188 | * @param [string] Column name. |
||
189 | * @param [attributes and values array] |
||
190 | */ |
||
191 | public function setColumnDetails($column, $attributes) |
||
195 | |||
196 | /** |
||
197 | * Order the columns in a certain way. |
||
198 | * |
||
199 | * @param [string] Column name. |
||
200 | * @param [attributes and values array] |
||
201 | */ |
||
202 | public function setColumnOrder($columns) |
||
206 | |||
207 | // ALIAS of setColumnOrder($columns) |
||
208 | public function setColumnsOrder($columns) |
||
212 | |||
213 | /** |
||
214 | * Get the relationships used in the CRUD columns. |
||
215 | * @return [array] Relationship names |
||
216 | */ |
||
217 | public function getColumnsRelationships() |
||
225 | |||
226 | // ------------ |
||
227 | // TONE FUNCTIONS - UNDOCUMENTED, UNTESTED, SOME MAY BE USED |
||
228 | // ------------ |
||
229 | // TODO: check them |
||
230 | |||
231 | public function getColumns() |
||
235 | |||
236 | public function orderColumns($order) |
||
240 | } |
||
241 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: