Builder::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 0
cts 5
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
crap 2
1
<?php
2
3
/**
4
 * This file is part of Packy.
5
 *
6
 * (c) Peter Nijssen
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace AppBundle\Menu;
13
14
use Knp\Menu\FactoryInterface;
15
use Knp\Menu\ItemInterface;
16
use Symfony\Component\Security\Core\Authorization\AuthorizationChecker;
17
18
class Builder
19
{
20
    /**
21
     * @var FactoryInterface
22
     */
23
    private $factory;
24
25
    /**
26
     * @var AuthorizationChecker
27
     */
28
    private $security;
29
30
    /**
31
     * @param FactoryInterface     $factory
32
     * @param AuthorizationChecker $security
33
     *
34
     * Add any other dependency you need
35
     */
36
    public function __construct(FactoryInterface $factory, AuthorizationChecker $security)
37
    {
38
        $this->factory = $factory;
39
        $this->security = $security;
40
    }
41
42
    /**
43
     * Create the side menu.
44
     *
45
     * @return ItemInterface
46
     */
47
    public function createSideMenu()
48
    {
49
        $menu = $this->factory->createItem('root');
50
        $menu->setChildrenAttribute('class', 'sidebar-menu');
51
52
        $menu->addChild(
53
            'Projects',
54
            [
55
                'route' => 'packy_project_overview',
56
                'extras' => [
57
                    'icon' => 'fa-tasks fa-fw',
58
                ],
59
            ]
60
        );
61
62
        if ($this->security->isGranted('ROLE_ADMIN')) {
63
            $menu->addChild(
64
                'Users',
65
                [
66
                    'route' => 'packy_user_overview',
67
                    'extras' => [
68
                        'icon' => 'fa-users fa-fw',
69
                    ],
70
                ]
71
            );
72
        }
73
74
        return $menu;
75
    }
76
}
77