Completed
Push — master ( 06c1ce...67d37c )
by Jeroen
06:20
created

TaggingBundle/Helper/Menu/TagMenuAdaptor.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\TaggingBundle\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
use Kunstmaan\AdminBundle\Helper\Menu\TopMenuItem;
9
use Symfony\Component\HttpFoundation\Request;
10
11 View Code Duplication
class TagMenuAdaptor implements MenuAdaptorInterface
0 ignored issues
show
This class seems to be duplicated in 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...
12
{
13
    /**
14
     * In this method you can add children for a specific parent, but also remove and change the already created children
15
     *
16
     * @param MenuBuilder $menu      The MenuBuilder
17
     * @param MenuItem[]  &$children The current children
18
     * @param MenuItem    $parent    The parent Menu item
19
     * @param Request     $request   The Request
20
     */
21
    public function adaptChildren(MenuBuilder $menu, array &$children, MenuItem $parent = null, Request $request = null)
22
    {
23
        if (!\is_null($parent) && 'KunstmaanAdminBundle_modules' == $parent->getRoute()) {
24
            $menuItem = new TopMenuItem($menu);
25
            $menuItem
26
                ->setRoute('kunstmaantaggingbundle_admin_tag')
27
                ->setUniqueId('Tags')
28
                ->setLabel('Tags')
29
                ->setParent($parent);
30
            if (stripos($request->attributes->get('_route'), $menuItem->getRoute()) === 0) {
31
                $menuItem->setActive(true);
32
                $parent->setActive(true);
33
            }
34
            $children[] = $menuItem;
35
        }
36
    }
37
}
38