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

AdminBundle/Helper/Menu/SettingsMenuAdaptor.php (2 issues)

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\HttpFoundation\Request;
6
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;
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 bool $isEnabledVersionChecker
27
     */
28 6
    public function __construct(AuthorizationCheckerInterface $authorizationChecker, $isEnabledVersionChecker)
29
    {
30 6
        $this->authorizationChecker = $authorizationChecker;
31 6
        $this->isEnabledVersionChecker = (bool) $isEnabledVersionChecker;
32 6
    }
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
0 ignored issues
show
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...
40
     * @param Request     $request   The Request
0 ignored issues
show
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...
41
     */
42 5
    public function adaptChildren(MenuBuilder $menu, array &$children, MenuItem $parent = null, Request $request = null)
43
    {
44 5
        if (\is_null($parent)) {
45 1
            $menuItem = new TopMenuItem($menu);
46
            $menuItem
47 1
                ->setRoute('KunstmaanAdminBundle_settings')
48 1
                ->setLabel('settings.title')
49 1
                ->setUniqueId('settings')
50 1
                ->setParent($parent)
51 1
                ->setRole('settings');
52 1
            if (stripos($request->attributes->get('_route'), $menuItem->getRoute()) === 0) {
53 1
                $menuItem->setActive(true);
54
            }
55 1
            $children[] = $menuItem;
56
        }
57
58 5
        if (!\is_null($parent) && 'KunstmaanAdminBundle_settings' == $parent->getRoute()) {
59 3
            if ($this->authorizationChecker->isGranted('ROLE_SUPER_ADMIN') && $this->isEnabledVersionChecker) {
60 2
                $menuItem = new MenuItem($menu);
61
                $menuItem
62 2
                    ->setRoute('KunstmaanAdminBundle_settings_bundle_version')
63 2
                    ->setLabel('settings.version.bundle')
64 2
                    ->setUniqueId('bundle_versions')
65 2
                    ->setParent($parent);
66 2
                if (stripos($request->attributes->get('_route'), $menuItem->getRoute()) === 0) {
67 1
                    $menuItem->setActive(true);
68
                }
69 2
                $children[] = $menuItem;
70
            }
71
72 3
            $menuItem = new MenuItem($menu);
73
            $menuItem
74 3
                ->setRoute('kunstmaanadminbundle_admin_exception')
75 3
                ->setLabel('settings.exceptions.title')
76 3
                ->setUniqueId('exceptions')
77 3
                ->setParent($parent);
78 3
            if (stripos($request->attributes->get('_route'), $menuItem->getRoute()) === 0) {
79 2
                $menuItem->setActive(true);
80 2
                $parent->setActive(true);
81
            }
82 3
            $children[] = $menuItem;
83
        }
84 5
    }
85
}
86