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 |
||
35 | class Select extends Column implements SelectInterface |
||
36 | { |
||
37 | /** |
||
38 | * @return string |
||
39 | */ |
||
40 | protected $foreignTable; |
||
41 | |||
42 | /** |
||
43 | * @return string |
||
44 | */ |
||
45 | protected $foreignTableWhere; |
||
46 | |||
47 | /** |
||
48 | * @return array |
||
49 | */ |
||
50 | protected $items; |
||
51 | |||
52 | /** |
||
53 | * @return int |
||
54 | */ |
||
55 | protected $maxItems; |
||
56 | |||
57 | /** |
||
58 | * @return int |
||
59 | */ |
||
60 | protected $minItems; |
||
61 | |||
62 | /** |
||
63 | * @return int |
||
64 | */ |
||
65 | protected $size; |
||
66 | |||
67 | /* |
||
68 | * @var string |
||
69 | */ |
||
70 | protected $foreignField; |
||
71 | |||
72 | /** |
||
73 | * Input constructor. |
||
74 | * |
||
75 | * @param string $columnName |
||
76 | * @param $configuration |
||
77 | */ |
||
78 | View Code Duplication | public function __construct($columnName, $configuration) |
|
89 | |||
90 | /** |
||
91 | * @return string |
||
92 | */ |
||
93 | public function getForeignTable() |
||
97 | |||
98 | /** |
||
99 | * @return string |
||
100 | */ |
||
101 | public function getForeignTableWhere() |
||
105 | |||
106 | /** |
||
107 | * @return array |
||
108 | */ |
||
109 | public function getItems() |
||
113 | |||
114 | /** |
||
115 | * @return int |
||
116 | */ |
||
117 | public function getMaxItems() |
||
121 | |||
122 | /** |
||
123 | * @return int |
||
124 | */ |
||
125 | public function getMinItems() |
||
129 | |||
130 | /** |
||
131 | * @return int |
||
132 | */ |
||
133 | public function getSize() |
||
137 | |||
138 | public function getForeignField() |
||
142 | } |
||
143 |
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.