Completed
Push — sf2.7 ( 18de34...b252b6 )
by Laurent
18:26
created

MenuBuilder::buildUserMenu()   B

Complexity

Conditions 3
Paths 4

Size

Total Lines 101
Code Lines 73

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 101
rs 8.2857
cc 3
eloc 73
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
namespace AppBundle\Menu;
3
4
use Knp\Menu\FactoryInterface;
5
use Symfony\Component\DependencyInjection\ContainerAware;
6
7
class MenuBuilder extends ContainerAware
8
{
9
    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...
10
    {
11
        $menu = $factory->createItem('root');
12
        $menu->setChildrenAttribute('class', 'nav navbar-nav');
13
 
14
        return $menu;
15
    }
16
 
17
    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...
18
    {
19
        $menu = $factory->createItem('root');
20
        $menu->setChildrenAttribute('class', 'nav navbar-nav navbar-right');
21
 
22
        $context = $this->container->get('security.context');
23
        if ($context->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
24
            /*
25
             *  Menu Administration
26
             */
27
            $menu->addChild('entities', array('label' => 'menu.configuration'))
28
                ->setExtra('translation_domain', 'messages')
29
                ->setAttribute('dropdown', true)
30
                ->setAttribute('class', 'multi-level')
31
                ->setAttribute('icon', 'glyphicon glyphicon-cog');
32
33
            $menu['entities']
34
                ->addChild('company', array(
35
                    'route' => 'admin_company',
36
                    'label' => 'gestock.settings.company.title'
37
                ))
38
                ->setExtra('translation_domain', 'messages')
39
                ->setAttribute('icon', 'glyphicon glyphicon-tower');
40
41
            $menu['entities']
42
                ->addChild('applcation', array(
43
                    'route' => 'admin_application',
44
                    'label' => 'gestock.settings.application.title'
45
                ))
46
                ->setExtra('translation_domain', 'messages')
47
                ->setAttribute('icon', 'glyphicon glyphicon-wrench');
48
49
            $divers = $menu['entities']
50
                ->addChild('divers', array('label' => 'gestock.settings.diverse.title'))
51
                ->setExtra('translation_domain', 'messages')
52
                ->setAttribute('dropdown', true)
53
                ->setAttribute('class', 'dropdown-submenu')
54
                ->setAttribute('icon', 'glyphicon glyphicon-info-sign');
55
            
56
            $divers
57
                ->addChild('familylog', array(
58
                    'route' => 'admin_familylog',
59
                    'label' => 'gestock.settings.diverse.familylog'
60
                ))
61
                ->setAttribute('icon', 'glyphicon glyphicon-tag');
62
63
            $divers
64
                ->addChild('subfamilylog', array(
65
                    'route' => 'admin_subfamilylog',
66
                    'label' => 'gestock.settings.diverse.subfamilylog'
67
                ))
68
                ->setAttribute('icon', 'glyphicon glyphicon-tags');
69
70
            $divers
71
                ->addChild('zonestorage', array(
72
                    'route' => 'admin_zonestorage',
73
                    'label' => 'gestock.settings.diverse.zonestorage'
74
                ))
75
                ->setAttribute('icon', 'glyphicon glyphicon-map-marker');
76
77
            $menu['entities']
78
                ->addChild('divider')
79
                ->setAttribute('class', 'divider');
80
81
            $menu['entities']
82
                ->addChild('users', array(
83
                    'route' => 'admin_users',
84
                    'label' => 'menu.users'))
85
                ->setAttribute('icon', 'glyphicon glyphicon-user');
86
87
            $menu['entities']
88
                ->addChild('groups', array(
89
                    'route' => 'admin_groups',
90
                    'label' => 'menu.groups'))
91
                ->setAttribute('icon', 'fa fa-users');
92
        }
93
        /*
94
         *  Menu Profile
95
         */
96
        if ($context->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
97
            $menu->addChild('profile', array(
98
                        'label' => $context->getToken()->getUser()->getUsername()))
99
                ->setAttribute('dropdown', true)
100
                ->setAttribute('icon', 'fa fa-user');
101
            
102
            $menu['profile']->addChild('layout.logout', array('route' => 'fos_user_security_logout'))
103
                ->setExtra('translation_domain', 'FOSUserBundle')
104
                ->setAttribute('icon', 'fa fa-unlink');
105
        } else {
106
            $menu->addChild('profile', array(
107
                        'label' => 'menu.administration'
108
                ))
109
                ->setExtra('translation_domain', 'messages')
110
                ->setAttribute('dropdown', true)
111
                ->setAttribute('icon', 'fa fa-user');
112
        }
113
        $menu['profile']->addChild('menu.other_login', array('route' => 'fos_user_security_login'))
114
            ->setAttribute('icon', 'fa fa-link');
115
 
116
        return $menu;
117
    }
118
 
119
}