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 |
||
29 | class RelationInspector extends Client |
||
30 | { |
||
31 | use InspectorTrait; |
||
32 | |||
33 | /** |
||
34 | * getClientType |
||
35 | * |
||
36 | * @see ClientInterface |
||
37 | */ |
||
38 | public function getClientType() |
||
42 | |||
43 | /** |
||
44 | * getClientIdentifier |
||
45 | * |
||
46 | * @see ClientInterface |
||
47 | */ |
||
48 | public function getClientIdentifier() |
||
52 | |||
53 | /** |
||
54 | * getRelations |
||
55 | * |
||
56 | * Return a list of relations. Be aware that if no conditions is given, it |
||
57 | * will also return system tables and views. |
||
58 | * |
||
59 | * @param Where $where |
||
60 | * @return ConvertedResultIterator |
||
61 | */ |
||
62 | View Code Duplication | public function getRelations(Where $where = null) |
|
98 | |||
99 | /** |
||
100 | * getRelationsInSchema |
||
101 | * |
||
102 | * Return the list of relations contained in the given schema. |
||
103 | * |
||
104 | * @param string $schema_name |
||
105 | * @param Where $where |
||
106 | * @return ConvertedResultIterator |
||
107 | */ |
||
108 | public function getRelationsInSchema($schema_name, Where $where = null) |
||
116 | |||
117 | /** |
||
118 | * getDatabaseRelations |
||
119 | * |
||
120 | * Return non system relations in the database. |
||
121 | * |
||
122 | * @param Where $where |
||
123 | * @return ConvertedResultIterator |
||
124 | */ |
||
125 | View Code Duplication | public function getDatabaseRelations(Where $where = null) |
|
134 | |||
135 | /** |
||
136 | * getTableFieldInformationWhere |
||
137 | * |
||
138 | * Get table's field information. If no fields are found, null is |
||
139 | * returned. |
||
140 | * |
||
141 | * @param Where $where |
||
142 | * @return ConvertedResultIterator |
||
143 | */ |
||
144 | View Code Duplication | protected function getTableFieldInformationWhere(Where $where) |
|
180 | |||
181 | /** |
||
182 | * getTableFieldInformation |
||
183 | * |
||
184 | * Return table fields information given the table oid. |
||
185 | * |
||
186 | * @param int $oid |
||
187 | * @return ConvertedResultIterator |
||
188 | */ |
||
189 | public function getTableFieldInformation($oid) |
||
196 | |||
197 | /** |
||
198 | * getTableFieldInformationName |
||
199 | * |
||
200 | * A short description here |
||
201 | * |
||
202 | * @param string $schema |
||
203 | * @param string $name |
||
204 | * @return ConvertedResultIterator |
||
205 | */ |
||
206 | public function getTableFieldInformationName($schema, $name) |
||
214 | |||
215 | /** |
||
216 | * getTableTotalSizeOnDisk |
||
217 | * |
||
218 | * Return the total size of the relation on disk. This size includes |
||
219 | * associated indexes size. |
||
220 | * |
||
221 | * @param string $schema |
||
222 | * @param string $name |
||
223 | * @return string |
||
224 | */ |
||
225 | public function getTableTotalSizeOnDisk($schema, $name) |
||
243 | } |
||
244 |
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.