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

SeoBundle/Helper/Menu/SeoManagementMenuAdaptor.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\SeoBundle\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 SeoManagementMenuAdaptor implements MenuAdaptorInterface
12
{
13
    /**
14
     * @var AuthorizationCheckerInterface
15
     */
16
    private $authorizationChecker;
17
18
    public function __construct(AuthorizationCheckerInterface $authorizationChecker)
19
    {
20
        $this->authorizationChecker = $authorizationChecker;
21
    }
22
23
    /**
24
     * In this method you can add children for a specific parent, but also remove and change the already created children
25
     *
26
     * @param MenuBuilder $menu      The MenuBuilder
27
     * @param MenuItem[]  &$children The current children
28
     * @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...
29
     * @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...
30
     */
31
    public function adaptChildren(MenuBuilder $menu, array &$children, MenuItem $parent = null, Request $request = null)
32
    {
33
        if (!\is_null($parent) && ('KunstmaanAdminBundle_settings' == $parent->getRoute()) && $this->authorizationChecker->isGranted('ROLE_SUPER_ADMIN')) {
34
            $menuItem = new MenuItem($menu);
35
            $menuItem
36
                ->setRoute('KunstmaanSeoBundle_settings_robots')
37
                ->setLabel('seo.robots.title')
38
                ->setUniqueId('robots_settings')
39
                ->setParent($parent);
40
            if (stripos($request->attributes->get('_route'), $menuItem->getRoute()) === 0) {
41
                $menuItem->setActive(true);
42
                $parent->setActive(true);
43
            }
44
            $children[] = $menuItem;
45
        }
46
    }
47
}
48