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 | class AdminltePresenter extends Presenter |
||
8 | { |
||
9 | /** |
||
10 | * {@inheritdoc }. |
||
11 | */ |
||
12 | public function getOpenTagWrapper() |
||
13 | { |
||
14 | return PHP_EOL . '<ul class="sidebar-menu tree" data-widget="tree">' . PHP_EOL; |
||
15 | } |
||
16 | |||
17 | /** |
||
18 | * {@inheritdoc }. |
||
19 | */ |
||
20 | public function getCloseTagWrapper() |
||
21 | { |
||
22 | return PHP_EOL . '</ul>' . PHP_EOL; |
||
23 | } |
||
24 | |||
25 | /** |
||
26 | * {@inheritdoc }. |
||
27 | */ |
||
28 | public function getMenuWithoutDropdownWrapper($item) |
||
31 | } |
||
32 | |||
33 | /** |
||
34 | * {@inheritdoc }. |
||
35 | */ |
||
36 | public function getActiveState($item, $state = ' class="active"') |
||
37 | { |
||
38 | return $item->isActive() ? $state : null; |
||
39 | } |
||
40 | |||
41 | /** |
||
42 | * Get active state on child items. |
||
43 | * |
||
44 | * @param $item |
||
45 | * @param string $state |
||
46 | * |
||
47 | * @return null|string |
||
48 | */ |
||
49 | public function getActiveStateOnChild($item, $state = 'active') |
||
50 | { |
||
51 | return $item->hasActiveOnChild() ? $state : null; |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * {@inheritdoc }. |
||
56 | */ |
||
57 | public function getDividerWrapper() |
||
58 | { |
||
59 | return '<li class="divider"></li>'; |
||
60 | } |
||
61 | |||
62 | /** |
||
63 | * {@inheritdoc }. |
||
64 | */ |
||
65 | public function getHeaderWrapper($item) |
||
68 | } |
||
69 | |||
70 | /** |
||
71 | * {@inheritdoc }. |
||
72 | */ |
||
73 | public function getMenuWithDropDownWrapper($item) |
||
87 | } |
||
88 | |||
89 | /** |
||
90 | * Get multilevel menu wrapper. |
||
91 | * |
||
92 | * @param \KyleMassacre\Menus\MenuItem $item |
||
93 | * |
||
94 | * @return string` |
||
|
|||
95 | */ |
||
96 | public function getMultiLevelDropdownWrapper($item) |
||
110 | } |
||
111 | } |
||
112 |