Completed
Push — master ( e62fa2...4391c3 )
by Kristof
133:20 queued 117:59
created

AdminBundle/Helper/Menu/SettingsMenuAdaptor.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 Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
6
use Symfony\Component\HttpFoundation\Request;
7
8
/**
9
 * SettingsMenuAdaptor to add the Settings MenuItem to the top menu and build the Settings tree
10
 */
11
class SettingsMenuAdaptor implements MenuAdaptorInterface
12
{
13
    /**
14
     * @var AuthorizationCheckerInterface
15
     */
16
    private $authorizationChecker;
17
18
    /**
19
     * @var bool
20
     */
21
    private $isEnabledVersionChecker;
22
23
    /**
24
     * Constructor
25
     *
26
     * @param AuthorizationCheckerInterface $container
0 ignored issues
show
There is no parameter named $container. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
27
     */
28
    public function __construct(AuthorizationCheckerInterface $authorizationChecker, $isEnabledVersionChecker)
29
    {
30
        $this->authorizationChecker = $authorizationChecker;
31
        $this->isEnabledVersionChecker = (bool) $isEnabledVersionChecker;
32
    }
33
34
    /**
35
     * In this method you can add children for a specific parent, but also remove and change the already created children
36
     *
37
     * @param MenuBuilder $menu      The MenuBuilder
38
     * @param MenuItem[]  &$children The current children
39
     * @param MenuItem    $parent    The parent Menu item
40
     * @param Request     $request   The Request
41
     */
42
    public function adaptChildren(MenuBuilder $menu, array &$children, MenuItem $parent = null, Request $request = null)
43
    {
44
        if (is_null($parent)) {
45
            $menuItem = new TopMenuItem($menu);
46
            $menuItem
47
                ->setRoute('KunstmaanAdminBundle_settings')
48
                ->setLabel('settings.title')
49
                ->setUniqueId('settings')
50
                ->setParent($parent)
51
                ->setRole('settings');
52
            if (stripos($request->attributes->get('_route'), $menuItem->getRoute()) === 0) {
53
                $menuItem->setActive(true);
54
            }
55
            $children[] = $menuItem;
56
        } elseif ('KunstmaanAdminBundle_settings' == $parent->getRoute()) {
57
            if ($this->authorizationChecker->isGranted('ROLE_SUPER_ADMIN')) {
58 View Code Duplication
                if ($this->isEnabledVersionChecker) {
59
                    $menuItem = new MenuItem($menu);
60
                    $menuItem
61
                        ->setRoute('KunstmaanAdminBundle_settings_bundle_version')
62
                        ->setLabel('settings.version.bundle')
63
                        ->setUniqueId('bundle_versions')
64
                        ->setParent($parent);
65
                    if (stripos($request->attributes->get('_route'), $menuItem->getRoute()) === 0) {
66
                        $menuItem->setActive(true);
67
                    }
68
                    $children[] = $menuItem;
69
                }
70
            }
71
        }
72
73
        if (!is_null($parent) && 'KunstmaanAdminBundle_settings' == $parent->getRoute()) {
74
            $menuItem = new MenuItem($menu);
75
            $menuItem
76
                ->setRoute('kunstmaanadminbundle_admin_exception')
77
                ->setLabel('settings.exceptions.title')
78
                ->setUniqueId('exceptions')
79
                ->setParent($parent);
80
            if (stripos($request->attributes->get('_route'), $menuItem->getRoute()) === 0) {
81
                $menuItem->setActive(true);
82
                $parent->setActive(true);
83
            }
84
            $children[] = $menuItem;
85
        }
86
    }
87
}
88