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   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 69
Duplicated Lines 34.78 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 5
dl 24
loc 69
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
B updateMenu() 24 51 7
A getMenuPriority() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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