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 |
||
13 | |||
14 | class MetronicHorizontalMenuPresenter extends Presenter |
||
15 | { |
||
16 | /** |
||
17 | * {@inheritdoc } |
||
18 | */ |
||
19 | public function getOpenTagWrapper(): ?string |
||
20 | { |
||
21 | return PHP_EOL . '<ul class="m-menu__nav m-menu__nav--submenu-arrow ">' . PHP_EOL; |
||
22 | } |
||
23 | |||
24 | /** |
||
25 | * {@inheritdoc } |
||
26 | */ |
||
27 | public function getCloseTagWrapper(): ?string |
||
28 | { |
||
29 | return PHP_EOL . '</ul>' . PHP_EOL; |
||
30 | } |
||
31 | |||
32 | /** |
||
33 | * {@inheritdoc } |
||
34 | */ |
||
35 | public function getMenuWithoutDropdownWrapper(MenuItemContract $item): ?string |
||
36 | { |
||
37 | return '<li ' . $this->getActiveState($item) . '>' . $item->getIcon() . '<a href="' . $item->getUrl() . '" class="m-menu__link"><span class="m-menu__item-here"></span><span class="m-menu__link-text">' . $item->title . '</span></a></li>'; |
||
38 | } |
||
39 | |||
40 | /** |
||
41 | * {@inheritdoc } |
||
42 | */ |
||
43 | public function getActiveState(MenuItemContract $item): string |
||
44 | { |
||
45 | return \Request::is($item->getRequest()) ? ' class="m-menu__item m-menu__item--rel active"' : 'class="m-menu__item m-menu__item--rel"'; |
||
46 | } |
||
47 | |||
48 | /** |
||
49 | * {@inheritdoc } |
||
50 | */ |
||
51 | public function getDividerWrapper(): ?string |
||
52 | { |
||
53 | return ''; |
||
54 | } |
||
55 | |||
56 | /** |
||
57 | * {@inheritdoc } |
||
58 | */ |
||
59 | public function getMenuWithDropDownWrapper(MenuItemContract $item): ?string |
||
92 | } |
||
93 | } |
||
94 | |||
95 | public function getMultiLevelDropdownWrapper(MenuItemContract $item): string |
||
113 | } |
||
114 | } |
||
115 |