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 |
||
4 | class Config |
||
5 | { |
||
6 | /** |
||
7 | * @var array |
||
8 | */ |
||
9 | protected $entityMap = []; |
||
10 | |||
11 | public function __construct(array $entityMap) |
||
15 | |||
16 | /** |
||
17 | * @param string $entityName |
||
18 | * |
||
19 | * @return string |
||
20 | */ |
||
21 | View Code Duplication | public function getTable($entityName) |
|
29 | |||
30 | /** |
||
31 | * @param string $entityName |
||
32 | * @return string |
||
33 | */ |
||
34 | View Code Duplication | public function getEntityClass($entityName) |
|
42 | |||
43 | /** |
||
44 | * @param string $entityName |
||
45 | * @return string |
||
46 | */ |
||
47 | public function getCollectionClass($entityName) |
||
55 | |||
56 | /** |
||
57 | * @param string $entityName |
||
58 | * @param string $attribute |
||
59 | * @return string |
||
60 | */ |
||
61 | public function getFiled($entityName, $attribute) |
||
77 | |||
78 | /** |
||
79 | * @param string $entityName |
||
80 | * @param string $joinEntityName |
||
81 | * |
||
82 | * @return string |
||
83 | */ |
||
84 | public function getRelationExpression($entityName, $joinEntityName) |
||
110 | |||
111 | /** |
||
112 | * @param string $entityName |
||
113 | * @param string $joinEntityName |
||
114 | * @return bool |
||
115 | */ |
||
116 | public function isRelationManyToMany($entityName, $joinEntityName) |
||
136 | |||
137 | /** |
||
138 | * @param string $entityName |
||
139 | * @param string $joinEntityName |
||
140 | * @return array |
||
141 | */ |
||
142 | public function getRelationManyToMany($entityName, $joinEntityName) |
||
160 | |||
161 | /** |
||
162 | * @param string $entityName |
||
163 | * |
||
164 | * @return array |
||
165 | */ |
||
166 | public function getColumnsAsAttributesMap($entityName) |
||
182 | |||
183 | /** |
||
184 | * @param string $entityName |
||
185 | * @return string|null |
||
186 | */ |
||
187 | public function getPrimaryKey($entityName) |
||
193 | |||
194 | /** |
||
195 | * @param string $entityName |
||
196 | * @return string|null |
||
197 | */ |
||
198 | public function getSequence($entityName) |
||
204 | |||
205 | /** |
||
206 | * @param string $entityName |
||
207 | * @return string|null |
||
208 | */ |
||
209 | public function getCriteriaMap($entityName) |
||
215 | |||
216 | /** |
||
217 | * @param string $entityName |
||
218 | * @return string |
||
219 | */ |
||
220 | public function getNamespace($entityName) |
||
228 | |||
229 | public function getCustomCriteriaClass($entityName, $criteriaName) |
||
240 | } |
||
241 |
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.