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 |
||
21 | class Shelf extends MagicAttributes |
||
22 | { |
||
23 | /** |
||
24 | * 控件1 |
||
25 | * |
||
26 | * @param int $count |
||
27 | * @param int $groupId |
||
28 | * @return $this |
||
29 | */ |
||
30 | View Code Duplication | public function controlOne($count, $groupId) |
|
44 | |||
45 | /** |
||
46 | * 控件2 |
||
47 | * |
||
48 | * @param array $groupId |
||
49 | * @return Shelf $this |
||
50 | * @throws ShopsException |
||
51 | */ |
||
52 | public function controlTwo(array $groupId) |
||
73 | |||
74 | /** |
||
75 | * 控件3 |
||
76 | * |
||
77 | * @param string $groupId |
||
78 | * @param string $img |
||
79 | * @return Shelf $this |
||
80 | */ |
||
81 | View Code Duplication | public function controlThree($groupId, $img) |
|
93 | |||
94 | /** |
||
95 | * 控件4 |
||
96 | * |
||
97 | * @param array $groups |
||
98 | * @return $this |
||
99 | * @throws ShopsException |
||
100 | */ |
||
101 | public function controlFour(array $groups) |
||
148 | |||
149 | /** |
||
150 | * 控件5 |
||
151 | * |
||
152 | * @param array $groups |
||
153 | * @param string $imgBackground |
||
154 | * @return $this |
||
155 | */ |
||
156 | public function controlFive(array $groups, $imgBackground) |
||
175 | } |