Completed
Pull Request — demo (#202)
by Loïc
02:17
created

AdminMenuBuilder   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 82
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A createMenu() 0 10 1
A addContentSubMenu() 0 12 1
A addCustomerSubMenu() 0 13 1
A addConfigurationSubMenu() 0 13 1
1
<?php
2
3
/*
4
 * This file is part of AppName.
5
 *
6
 * (c) Monofony
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 App\Menu;
13
14
use Knp\Menu\FactoryInterface;
15
use Knp\Menu\ItemInterface;
16
use Symfony\Component\HttpFoundation\RequestStack;
17
18
final class AdminMenuBuilder
19
{
20
    /**
21
     * @var FactoryInterface
22
     */
23
    private $factory;
24
25
    /**
26
     * @param FactoryInterface $factory
27
     */
28
    public function __construct(FactoryInterface $factory)
29
    {
30
        $this->factory = $factory;
31
    }
32
33
    /**
34
     * @param RequestStack $requestStack
35
     *
36
     * @return ItemInterface
37
     */
38
    public function createMenu(RequestStack $requestStack)
0 ignored issues
show
Unused Code introduced by
The parameter $requestStack is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
39
    {
40
        $menu = $this->factory->createItem('root');
41
42
        $this->addContentSubMenu($menu);
43
        $this->addCustomerSubMenu($menu);
44
        $this->addConfigurationSubMenu($menu);
45
46
        return $menu;
47
    }
48
49
    private function addContentSubMenu(ItemInterface $menu): ItemInterface
50
    {
51
        $customer = $menu
52
            ->addChild('content')
53
            ->setLabel('sylius.ui.content');
54
55
        $customer->addChild('backend_article', ['route' => 'app_backend_article_index'])
56
            ->setLabel('app.ui.articles')
57
            ->setLabelAttribute('icon', 'newspaper');
58
59
        return $customer;
60
    }
61
62
    /**
63
     * @param ItemInterface $menu
64
     *
65
     * @return ItemInterface
66
     */
67
    private function addCustomerSubMenu(ItemInterface $menu)
68
    {
69
        $customer = $menu
70
            ->addChild('customer')
71
            ->setLabel('sylius.ui.customer')
72
        ;
73
74
        $customer->addChild('backend_customer', ['route' => 'sylius_backend_customer_index'])
75
            ->setLabel('sylius.ui.customers')
76
            ->setLabelAttribute('icon', 'users');
77
78
        return $customer;
79
    }
80
81
    /**
82
     * @param ItemInterface $menu
83
     *
84
     * @return ItemInterface
85
     */
86
    private function addConfigurationSubMenu(ItemInterface $menu)
87
    {
88
        $configuration = $menu
89
            ->addChild('configuration')
90
            ->setLabel('sylius.ui.configuration')
91
        ;
92
93
        $configuration->addChild('backend_admin_user', ['route' => 'sylius_backend_admin_user_index'])
94
            ->setLabel('sylius.ui.admin_users')
95
            ->setLabelAttribute('icon', 'lock');
96
97
        return $configuration;
98
    }
99
}
100