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 |
||
7 | abstract class Presenter implements PresenterInterface |
||
8 | { |
||
9 | /** |
||
10 | * Get open tag wrapper. |
||
11 | * |
||
12 | * @return string |
||
13 | */ |
||
14 | public function getOpenTagWrapper() |
||
17 | |||
18 | /** |
||
19 | * Get close tag wrapper. |
||
20 | * |
||
21 | * @return string |
||
22 | */ |
||
23 | public function getCloseTagWrapper() |
||
27 | |||
28 | /** |
||
29 | * Get open tag A. |
||
30 | * |
||
31 | * @return string |
||
32 | */ |
||
33 | View Code Duplication | public function getOpenTagA($item) |
|
40 | |||
41 | /** |
||
42 | * Get close tag A. |
||
43 | * |
||
44 | * @return string |
||
45 | */ |
||
46 | View Code Duplication | public function getCloseTagA($item) |
|
53 | |||
54 | |||
55 | /** |
||
56 | * Get menu tag without dropdown wrapper. |
||
57 | * |
||
58 | * @param \Nwidart\Menus\MenuItem $item |
||
59 | * |
||
60 | * @return string |
||
61 | */ |
||
62 | public function getMenuWithoutDropdownWrapper($item) |
||
65 | |||
66 | /** |
||
67 | * Get divider tag wrapper. |
||
68 | * |
||
69 | * @return string |
||
70 | */ |
||
71 | public function getDividerWrapper() |
||
74 | |||
75 | /** |
||
76 | * Get header dropdown tag wrapper. |
||
77 | * |
||
78 | * @param \Nwidart\Menus\MenuItem $item |
||
79 | * |
||
80 | * @return string |
||
81 | */ |
||
82 | public function getHeaderWrapper($item) |
||
85 | |||
86 | /** |
||
87 | * Get menu tag with dropdown wrapper. |
||
88 | * |
||
89 | * @param \Nwidart\Menus\MenuItem $item |
||
90 | * |
||
91 | * @return string |
||
92 | */ |
||
93 | public function getMenuWithDropDownWrapper($item) |
||
96 | |||
97 | /** |
||
98 | * Get multi level dropdown menu wrapper. |
||
99 | * |
||
100 | * @param \Nwidart\Menus\MenuItem $item |
||
101 | * |
||
102 | * @return string |
||
103 | */ |
||
104 | public function getMultiLevelDropdownWrapper($item) |
||
107 | |||
108 | /** |
||
109 | * Get child menu items. |
||
110 | * |
||
111 | * @param \Nwidart\Menus\MenuItem $item |
||
112 | * |
||
113 | * @return string |
||
114 | */ |
||
115 | public function getChildMenuItems(MenuItem $item) |
||
136 | } |
||
137 |
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.