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\ConfigBundle\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 Symfony\Component\HttpFoundation\Request; |
||
9 | use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; |
||
10 | |||
11 | class ConfigMenuAdaptor implements MenuAdaptorInterface |
||
12 | { |
||
13 | /** |
||
14 | * @var array |
||
15 | */ |
||
16 | private $configuration; |
||
17 | |||
18 | /** |
||
19 | * @var AuthorizationCheckerInterface |
||
20 | */ |
||
21 | private $authorizationChecker; |
||
22 | |||
23 | /** |
||
24 | * @param array $configuration |
||
25 | * @param AuthorizationCheckerInterface $authorizationChecker |
||
26 | */ |
||
27 | public function __construct($configuration, AuthorizationCheckerInterface $authorizationChecker) |
||
28 | { |
||
29 | $this->configuration = $configuration; |
||
30 | $this->authorizationChecker = $authorizationChecker; |
||
31 | } |
||
32 | |||
33 | /** |
||
34 | * In this method you can add children for a specific parent, but also remove and change the already created children |
||
35 | * |
||
36 | * @param MenuBuilder $menu The MenuBuilder |
||
37 | * @param MenuItem[] &$children The current children |
||
38 | * @param MenuItem $parent The parent Menu item |
||
0 ignored issues
–
show
|
|||
39 | * @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...
|
|||
40 | */ |
||
41 | public function adaptChildren(MenuBuilder $menu, array &$children, MenuItem $parent = null, Request $request = null) |
||
42 | { |
||
43 | if (!\is_null($parent) && 'KunstmaanAdminBundle_settings' == $parent->getRoute()) { |
||
44 | // Load all the kunstmaan_config entities and create a menu item for them. |
||
45 | foreach ($this->configuration['entities'] as $class) { |
||
46 | $entity = new $class(); |
||
47 | |||
48 | $hasAccess = false; |
||
49 | foreach ($entity->getRoles() as $role) { |
||
50 | if ($this->authorizationChecker->isGranted($role)) { |
||
51 | $hasAccess = true; |
||
52 | } |
||
53 | } |
||
54 | |||
55 | if ($hasAccess) { |
||
56 | $menuItem = new MenuItem($menu); |
||
57 | $menuItem |
||
58 | ->setRoute('kunstmaanconfigbundle_default') |
||
59 | ->setRouteParams(array('internalName' => $entity->getInternalName())) |
||
60 | ->setLabel($entity->getLabel()) |
||
61 | ->setUniqueId($entity->getInternalName()) |
||
62 | ->setParent($parent); |
||
63 | |||
64 | if ($request->attributes->get('_route') === $menuItem->getRoute() && $request->attributes->get('internalName') === $entity->getInternalName()) { |
||
65 | $menuItem->setActive(true); |
||
66 | $parent->setActive(true); |
||
67 | } |
||
68 | $children[] = $menuItem; |
||
69 | } |
||
70 | } |
||
71 | } |
||
72 | } |
||
73 | } |
||
74 |
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.