Completed
Pull Request — 5.6 (#2830)
by Jeroen
14:14
created

MenuAdaptor::adaptChildren()   A

Complexity

Conditions 5
Paths 3

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 0
cts 16
cp 0
rs 9.4222
c 0
b 0
f 0
cc 5
nc 3
nop 4
crap 30
1
<?php
2
3
namespace Kunstmaan\MenuBundle\Service;
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
class MenuAdaptor implements MenuAdaptorInterface
12
{
13
    /**
14
     * @var array
15
     */
16
    private $menuNames;
17
18
    public function __construct(array $menuNames)
19
    {
20
        $this->menuNames = $menuNames;
21
    }
22
23
    /**
24
     * @param MenuItem $parent
0 ignored issues
show
Documentation introduced by
Should the type for parameter $parent not be null|MenuItem?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
25
     * @param Request  $request
0 ignored issues
show
Documentation introduced by
Should the type for parameter $request not be null|Request?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
26
     */
27
    public function adaptChildren(MenuBuilder $menu, array &$children, MenuItem $parent = null, Request $request = null)
28
    {
29
        if ((count($this->menuNames) > 0) && null !== $parent && 'KunstmaanAdminBundle_modules' === $parent->getRoute()) {
30
            $menuItem = new TopMenuItem($menu);
31
            $menuItem
32
                ->setRoute('kunstmaanmenubundle_admin_menu')
33
                ->setUniqueId('menus')
34
                ->setLabel('kuma_menu.menus.title')
35
                ->setParent($parent);
36
            if ($request->attributes->get('_route') === 'kunstmaanmenubundle_admin_menu') {
37
                $menuItem->setActive(true);
38
                $parent->setActive(true);
39
            }
40
            $children[] = $menuItem;
41
        }
42
    }
43
}
44