Completed
Push — master ( 91fdab...75a7b9 )
by
unknown
13:37
created

AdminBundle/Helper/Menu/ModulesMenuAdaptor.php (1 issue)

Upgrade to new PHP Analysis Engine

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 Kunstmaan\AdminBundle\Helper\Menu\MenuAdaptorInterface;
6
use Kunstmaan\AdminBundle\Helper\Menu\MenuBuilder;
7
use Kunstmaan\AdminBundle\Helper\Menu\MenuItem;
8
9
use Symfony\Component\HttpFoundation\Request;
10
11
/**
12
 * MenuAdaptor to add the Modules MenuItem to the top menu
13
 */
14
class ModulesMenuAdaptor implements MenuAdaptorInterface
15
{
16
    /**
17
     * In this method you can add children for a specific parent, but also remove and change the already created children
18
     *
19
     * @param MenuBuilder $menu      The MenuBuilder
20
     * @param MenuItem[]  &$children The current children
21
     * @param MenuItem    $parent    The parent Menu item
22
     * @param Request     $request   The Request
23
     */
24
    public function adaptChildren(MenuBuilder $menu, array &$children, MenuItem $parent = null, Request $request = null)
25
    {
26 View Code Duplication
        if (is_null($parent)) {
0 ignored issues
show
This code seems to be duplicated across your project.

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.

Loading history...
27
            $menuItem = new TopMenuItem($menu);
28
            $menuItem
29
                ->setRoute('KunstmaanAdminBundle_modules')
30
                ->setLabel('modules.title')
31
                ->setUniqueId('modules')
32
                ->setParent($parent);
33
            if (stripos($request->attributes->get('_route'), $menuItem->getRoute()) === 0) {
34
                $menuItem->setActive(true);
35
            }
36
            $children[] = $menuItem;
37
        }
38
    }
39
40
}
41