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 |
||
9 | trait TEntitySetAttributesTrait |
||
10 | { |
||
11 | use TSimpleIdentifierTrait, TQualifiedNameTrait, AccessTypeTraits; |
||
12 | /** |
||
13 | * @property string $name |
||
14 | */ |
||
15 | private $name = null; |
||
16 | |||
17 | /** |
||
18 | * @property string $entityType |
||
19 | */ |
||
20 | private $entityType = null; |
||
21 | |||
22 | /** |
||
23 | * @property string $getterAccess |
||
24 | */ |
||
25 | private $getterAccess = null; |
||
26 | |||
27 | /** |
||
28 | * Gets as name |
||
29 | * |
||
30 | * @return string |
||
31 | */ |
||
32 | public function getName() |
||
36 | |||
37 | /** |
||
38 | * Sets a new name |
||
39 | * |
||
40 | * @param string $name |
||
41 | * @return self |
||
42 | */ |
||
43 | public function setName($name) |
||
48 | |||
49 | /** |
||
50 | * Gets as entityType |
||
51 | * |
||
52 | * @return string |
||
53 | */ |
||
54 | public function getEntityType() |
||
58 | |||
59 | /** |
||
60 | * Sets a new entityType |
||
61 | * |
||
62 | * @param string $entityType |
||
63 | * @return self |
||
64 | */ |
||
65 | public function setEntityType($entityType) |
||
70 | |||
71 | /** |
||
72 | * Gets as getterAccess |
||
73 | * |
||
74 | * @return string |
||
75 | */ |
||
76 | public function getGetterAccess() |
||
80 | |||
81 | /** |
||
82 | * Sets a new getterAccess |
||
83 | * |
||
84 | * @param string $getterAccess |
||
85 | * @return self |
||
86 | */ |
||
87 | public function setGetterAccess($getterAccess) |
||
92 | |||
93 | |||
94 | public function isTEntitySetAttributesOK(&$msg = null) |
||
111 | } |
||
112 |
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.