These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Kunstmaan\AdminBundle\Helper\Menu; |
||
4 | |||
5 | use Symfony\Component\HttpFoundation\Request; |
||
6 | |||
7 | /** |
||
8 | * MenuAdaptor to add the Modules MenuItem to the top menu |
||
9 | */ |
||
10 | class ModulesMenuAdaptor implements MenuAdaptorInterface |
||
11 | { |
||
12 | /** |
||
13 | * In this method you can add children for a specific parent, but also remove and change the already created children |
||
14 | * |
||
15 | * @param MenuBuilder $menu The MenuBuilder |
||
16 | * @param MenuItem[] &$children The current children |
||
17 | * @param MenuItem $parent The parent Menu item |
||
18 | * @param Request $request The Request |
||
19 | */ |
||
20 | public function adaptChildren(MenuBuilder $menu, array &$children, MenuItem $parent = null, Request $request = null) |
||
21 | { |
||
22 | View Code Duplication | if (is_null($parent)) { |
|
0 ignored issues
–
show
|
|||
23 | $menuItem = new TopMenuItem($menu); |
||
24 | $menuItem |
||
25 | ->setRoute('KunstmaanAdminBundle_modules') |
||
26 | ->setLabel('modules.title') |
||
27 | ->setUniqueId('modules') |
||
28 | ->setParent($parent); |
||
29 | if (stripos($request->attributes->get('_route'), $menuItem->getRoute()) === 0) { |
||
30 | $menuItem->setActive(true); |
||
31 | } |
||
32 | $children[] = $menuItem; |
||
33 | } |
||
34 | } |
||
35 | } |
||
36 |
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.