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 |
||
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 |
||
0 ignored issues
–
show
|
|||
40 | * @param Request $request The Request |
||
0 ignored issues
–
show
Should the type for parameter
$request not be null|Request ?
This check looks for 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 | 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 |
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.