GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

StudentTrackingMenu::updateMenu()   B
last analyzed

Complexity

Conditions 7
Paths 16

Size

Total Lines 51

Duplication

Lines 24
Ratio 47.06 %

Importance

Changes 0
Metric Value
dl 24
loc 51
rs 8.1357
c 0
b 0
f 0
cc 7
nc 16
nop 1

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
  ÁTICA - Aplicación web para la gestión documental de centros educativos
4
5
  Copyright (C) 2015-2016: Luis Ramón López López
6
7
  This program is free software: you can redistribute it and/or modify
8
  it under the terms of the GNU Affero General Public License as published by
9
  the Free Software Foundation, either version 3 of the License, or
10
  (at your option) any later version.
11
12
  This program is distributed in the hope that it will be useful,
13
  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
  GNU Affero General Public License for more details.
16
17
  You should have received a copy of the GNU Affero General Public License
18
  along with this program.  If not, see [http://www.gnu.org/licenses/].
19
*/
20
21
namespace AppBundle\Service;
22
23
use AppBundle\Entity\User;
24
use AppBundle\Menu\MenuItem;
25
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
26
use Symfony\Component\Security\Core\Authorization\AuthorizationChecker;
27
28
class StudentTrackingMenu implements MenuBuilderInterface
29
{
30
    private $tokenStorage;
31
    private $authorizationChecker;
32
33
34
    public function __construct(AuthorizationChecker $authorizationChecker, TokenStorageInterface $tokenStorage)
35
    {
36
        $this->authorizationChecker = $authorizationChecker;
37
        $this->tokenStorage = $tokenStorage;
38
    }
39
40
    public function updateMenu(&$menu)
41
    {
42
        /** @var User $user */
43
        $user = $this->tokenStorage->getToken()->getUser();
44
45
        /**
46
         * @var $root MenuItem
47
         */
48
        $root = reset($menu);
49
50
        if ($user->getEducationalTutorAgreements()->count() !== 0 || $user->getWorkTutorAgreements()->count() !== 0) {
51
            $menuItem = new MenuItem();
52
            $menuItem
53
                ->setName('my_students_tracking')
54
                ->setRouteName('my_student_index')
55
                ->setCaption('menu.student_tracking')
56
                ->setDescription('menu.student_tracking.detail')
57
                ->setColor('orange')
58
                ->setIcon('briefcase');
59
60
            $root->addChild($menuItem, MenuItem::AT_THE_END);
61
        }
62
63
        $check = ($this->authorizationChecker->isGranted('ROLE_DEPARTMENT_HEAD') || $user->getEducationalTutorAgreements()->count() !== 0);
64
65 View Code Duplication
        if ($check) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
66
            $menuItem = new MenuItem();
67
            $menuItem
68
                ->setName('my_students_visit')
69
                ->setRouteName('visit_index')
70
                ->setCaption('menu.student_visit')
71
                ->setDescription('menu.student_visit.detail')
72
                ->setColor('yellow')
73
                ->setIcon('car');
74
75
            $root->addChild($menuItem, MenuItem::AT_THE_END);
76
        }
77
78 View Code Duplication
        if ($this->authorizationChecker->isGranted('ROLE_FINANCIAL_MANAGER') || $check) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
79
            $menuItem = new MenuItem();
80
            $menuItem
81
                ->setName('travel_expenses')
82
                ->setRouteName('expense_tutor_index')
83
                ->setCaption('menu.travel_expenses')
84
                ->setDescription('menu.travel_expenses.detail')
85
                ->setColor('cyan')
86
                ->setIcon('road');
87
88
            $root->addChild($menuItem, MenuItem::AT_THE_END);
89
        }
90
    }
91
92
    public function getMenuPriority()
93
    {
94
        return '0075-Student-Tracking';
95
    }
96
}
97