Completed
Push — master ( 5fd068...fdcd72 )
by Laurent
17s
created

MenuBuilder::buildUserMenu()   B

Complexity

Conditions 3
Paths 4

Size

Total Lines 108
Code Lines 78

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 0 Features 2
Metric Value
c 4
b 0
f 2
dl 0
loc 108
rs 8.2857
cc 3
eloc 78
nc 4
nop 2

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * MenuBuilder KnpMenu.
4
 *
5
 * PHP Version 5
6
 *
7
 * @author     Quétier Laurent <[email protected]>
8
 * @copyright  2014 Dev-Int GLSR
9
 * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
10
 *
11
 * @version    since 1.0.0
12
 *
13
 * @link       https://github.com/Dev-Int/glsr
14
 */
15
namespace AppBundle\Menu;
16
17
use Knp\Menu\FactoryInterface;
18
use Symfony\Component\DependencyInjection\ContainerAware;
19
20
/**
21
 * class MenuBuilder.
22
 *
23
 * @category   Menu
24
 */
25
class MenuBuilder extends ContainerAware
26
{
27
    public function buildMainMenu(FactoryInterface $factory, array $options)
0 ignored issues
show
Unused Code introduced by
The parameter $options 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...
28
    {
29
        $menu = $factory->createItem('root');
30
        $menu->setChildrenAttribute('class', 'nav navbar-nav');
31
        
32
        $menu->addChild('manage', array('label' => 'menu.management'))
33
            ->setExtra('translation_domain', 'messages')
34
            ->setAttribute('dropdown', true)
35
            ->setAttribute('icon', 'fa fa-dashboard');
36
        
37
        $menu['manage']->addChild('suppliers', array(
38
            'label' => 'title',
39
            'route' => 'suppliers'
40
        ))
41
            ->setExtra('translation_domain', 'gs_suppliers')
42
            ->setAttribute('icon', 'fa fa-barcode');
43
 
44
        $menu['manage']->addChild('articles', array(
45
            'label' => 'title',
46
            'route' => 'articles'
47
        ))
48
            ->setExtra('translation_domain', 'gs_articles')
49
            ->setAttribute('icon', 'fa fa-shopping-basket');
50
 
51
        $menu['manage']->addChild('inventory', array(
52
            'label' => 'title',
53
            'route' => 'inventory'
54
        ))
55
            ->setExtra('translation_domain', 'gs_inventories')
56
            ->setAttribute('icon', 'fa fa-tasks');
57
58
            return $menu;
59
    }
60
 
61
    public function buildUserMenu(FactoryInterface $factory, array $options)
0 ignored issues
show
Unused Code introduced by
The parameter $options 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...
62
    {
63
        $menu = $factory->createItem('root');
64
        $menu->setChildrenAttribute('class', 'nav navbar-nav navbar-right');
65
 
66
        $context = $this->container->get('security.context');
67
        if ($context->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
68
            /*
69
             *  Menu Administration
70
             */
71
            $menu->addChild('entities', array('label' => 'menu.configuration'))
72
                ->setExtra('translation_domain', 'messages')
73
                ->setAttribute('dropdown', true)
74
                ->setAttribute('class', 'multi-level')
75
                ->setAttribute('icon', 'glyphicon glyphicon-cog');
76
77
            $menu['entities']
78
                ->addChild('company', array(
79
                    'route' => 'admin_company',
80
                    'label' => 'gestock.settings.company.title'
81
                ))
82
                ->setExtra('translation_domain', 'messages')
83
                ->setAttribute('icon', 'glyphicon glyphicon-tower');
84
85
            $menu['entities']
86
                ->addChild('applcation', array(
87
                    'route' => 'admin_application',
88
                    'label' => 'gestock.settings.application.title'
89
                ))
90
                ->setExtra('translation_domain', 'messages')
91
                ->setAttribute('icon', 'glyphicon glyphicon-wrench');
92
93
            $divers = $menu['entities']
94
                ->addChild('divers', array('label' => 'gestock.settings.diverse.title'))
95
                ->setExtra('translation_domain', 'messages')
96
                ->setAttribute('dropdown', true)
97
                ->setAttribute('class', 'dropdown-submenu')
98
                ->setAttribute('icon', 'glyphicon glyphicon-info-sign');
99
            
100
            $divers
101
                ->addChild('familylog', array(
102
                    'route' => 'admin_familylog',
103
                    'label' => 'gestock.settings.diverse.familylog'
104
                ))
105
                ->setAttribute('icon', 'glyphicon glyphicon-tag');
106
107
            $divers
108
                ->addChild('zonestorage', array(
109
                    'route' => 'admin_zonestorage',
110
                    'label' => 'gestock.settings.diverse.zonestorage'
111
                ))
112
                ->setAttribute('icon', 'glyphicon glyphicon-map-marker');
113
114
            $divers
115
                ->addChild('unitstorage', array(
116
                    'route' => 'admin_unitstorage',
117
                    'label' => 'gestock.settings.diverse.unitstorage'
118
                ))
119
                ->setAttribute('icon', 'fa fa-cubes');
120
121
            $divers
122
                ->addChild('tva', array(
123
                    'route' => 'admin_rate',
124
                    'label' => 'gestock.settings.diverse.vat'
125
                ))
126
                ->setAttribute('icon', 'glyphicon glyphicon-piggy-bank');
127
128
            $menu['entities']
129
                ->addChild('divider')
130
                ->setAttribute('class', 'divider');
131
132
            $menu['entities']
133
                ->addChild('users', array(
134
                    'route' => 'admin_users',
135
                    'label' => 'menu.users'))
136
                ->setAttribute('icon', 'glyphicon glyphicon-user');
137
138
            $menu['entities']
139
                ->addChild('groups', array(
140
                    'route' => 'admin_groups',
141
                    'label' => 'menu.groups'))
142
                ->setAttribute('icon', 'fa fa-users');
143
        }
144
        /*
145
         *  Menu Profile
146
         */
147
        if ($context->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
148
            $menu->addChild('profile', array(
149
                        'label' => $context->getToken()->getUser()->getUsername()))
150
                ->setAttribute('dropdown', true)
151
                ->setAttribute('icon', 'fa fa-user');
152
            
153
            $menu['profile']->addChild('layout.logout', array('route' => 'fos_user_security_logout'))
154
                ->setExtra('translation_domain', 'FOSUserBundle')
155
                ->setAttribute('icon', 'fa fa-unlink');
156
        } else {
157
            $menu->addChild('profile', array(
158
                        'label' => 'menu.administration'
159
                ))
160
                ->setExtra('translation_domain', 'messages')
161
                ->setAttribute('dropdown', true)
162
                ->setAttribute('icon', 'fa fa-user');
163
        }
164
        $menu['profile']->addChild('menu.other_login', array('route' => 'fos_user_security_login'))
165
            ->setAttribute('icon', 'fa fa-link');
166
 
167
        return $menu;
168
    }
169
}
170