Completed
Push — master ( 6d6774...64f3ed )
by Jeroen
11:23 queued 05:13
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
    /**
19
     * @param AuthorizationCheckerInterface $authorizationChecker
20
     */
21
    public function __construct(AuthorizationCheckerInterface $authorizationChecker)
22
    {
23
        $this->authorizationChecker = $authorizationChecker;
24
    }
25
26
    /**
27
     * In this method you can add children for a specific parent, but also remove and change the already created children
28
     *
29
     * @param MenuBuilder $menu      The MenuBuilder
30
     * @param MenuItem[]  &$children The current children
31
     * @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...
32
     * @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...
33
     */
34
    public function adaptChildren(MenuBuilder $menu, array &$children, MenuItem $parent = null, Request $request = null)
35
    {
36
        if (!\is_null($parent) && ('KunstmaanAdminBundle_settings' == $parent->getRoute()) && $this->authorizationChecker->isGranted('ROLE_SUPER_ADMIN')) {
37
            $menuItem = new MenuItem($menu);
38
            $menuItem
39
                ->setRoute('KunstmaanSeoBundle_settings_robots')
40
                ->setLabel('seo.robots.title')
41
                ->setUniqueId('robots_settings')
42
                ->setParent($parent);
43
            if (stripos($request->attributes->get('_route'), $menuItem->getRoute()) === 0) {
44
                $menuItem->setActive(true);
45
                $parent->setActive(true);
46
            }
47
            $children[] = $menuItem;
48
        }
49
    }
50
}
51