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.
Completed
Push — master ( cddece...946e53 )
by Luis Ramón
03:29
created

ActivityController   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 147
Duplicated Lines 16.33 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 12
c 1
b 0
f 0
lcom 1
cbo 8
dl 24
loc 147
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A teachingIndexAction() 0 16 1
A formNewAction() 0 8 1
B formAction() 12 37 5
B groupIndexAction() 0 30 1
B activityDeleteAction() 12 33 4

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\Controller;
22
23
use AppBundle\Entity\Activity;
24
use AppBundle\Entity\Training;
25
use Doctrine\ORM\EntityManager;
26
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
27
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
28
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
29
use Symfony\Component\HttpFoundation\Request;
30
31
/**
32
 * @Route("/programa")
33
 * @Security("is_granted('ROLE_DEPARTMENT_HEAD')")
34
 */
35
class ActivityController extends Controller
36
{
37
    /**
38
     * @Route("", name="admin_program", methods={"GET"})
39
     */
40
    public function teachingIndexAction()
41
    {
42
        /** @var EntityManager $em */
43
        $em = $this->getDoctrine()->getManager();
44
45
        $teachingQuery = $em->createQuery('SELECT t FROM AppBundle:Training t ORDER BY t.name');
46
47
        $items = $teachingQuery->getResult();
48
49
        return $this->render('activity/training_index.html.twig',
50
            [
51
                'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('admin_program'),
52
                'title' => null,
53
                'elements' => $items
54
            ]);
55
    }
56
57
    /**
58
     * @Route("/{id}", name="admin_program_training", methods={"GET"})
59
     */
60
    public function groupIndexAction(Training $training, Request $request)
61
    {
62
        /** @var EntityManager $em */
63
        $em = $this->getDoctrine()->getManager();
64
65
        $usersQuery = $em->createQuery('SELECT a FROM AppBundle:Activity a WHERE a.training = :training')
66
            ->setParameter('training', $training);
67
68
        $paginator  = $this->get('knp_paginator');
69
        $pagination = $paginator->paginate(
70
            $usersQuery,
71
            $request->query->getInt('page', 1),
72
            $this->getParameter('page.size'),
73
            [
74
                'defaultSortFieldName' => 'a.code',
75
                'defaultSortDirection' => 'asc'
76
            ]
77
        );
78
79
        return $this->render('activity/manage_activities.html.twig',
80
            [
81
                'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('admin_program'),
82
                'breadcrumb' => [
83
                    ['fixed' => $training->getName(), 'path' => 'admin_program_training', 'options' => ['id' => $training->getId()]],
84
                ],
85
                'title' => $training->getName(),
86
                'pagination' => $pagination,
87
                'training' => $training
88
            ]);
89
    }
90
91
92
    /**
93
     * @Route("/{training}/nuevo", name="admin_program_activity_new", methods={"GET", "POST"}, requirements={"training": "\d+"})
94
     */
95
    public function formNewAction(Training $training, Request $request)
96
    {
97
        $activity = new Activity();
98
        $activity->setTraining($training);
99
        $this->getDoctrine()->getManager()->persist($activity);
100
101
        return $this->formAction($activity, $request);
102
    }
103
104
    /**
105
     * @Route("/actividad/{id}", name="admin_program_activity_form", methods={"GET", "POST"}, requirements={"activity": "\d+"})
106
     */
107
    public function formAction(Activity $activity, Request $request)
108
    {
109
        $em = $this->getDoctrine()->getManager();
110
111
        $form = $this->createForm('AppBundle\Form\Type\ActivityType', $activity, [
112
            'fixed' => true
113
        ]);
114
        
115
        $form->handleRequest($request);
116
117 View Code Duplication
        if ($form->isSubmitted() && $form->isValid()) {
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...
118
119
            // Guardar el usuario en la base de datos
120
            // Probar a guardar los cambios
121
            try {
122
                $em->flush();
123
                $this->addFlash('success', $this->get('translator')->trans('alert.saved', [], 'activity'));
124
                return $this->redirectToRoute('admin_program_training', ['id' => $activity->getTraining()->getId()]);
125
            } catch (\Exception $e) {
126
                $this->addFlash('error', $this->get('translator')->trans('alert.not_saved', [], 'activity'));
127
            }
128
        }
129
130
        $titulo = $activity->getId() ? $activity->getName() : $this->get('translator')->trans('form.new', [], 'activity');
131
132
        return $this->render('activity/form_activity.twig', [
133
            'form' => $form->createView(),
134
            'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('admin_program'),
135
            'breadcrumb' => [
136
                ['fixed' => $activity->getTraining()->getName(), 'path' => 'admin_program_training', 'options' => ['id' => $activity->getTraining()->getId()]],
137
                ['fixed' => $titulo]
138
            ],
139
            'new' => ($activity->getId() == 0),
140
            'title' => $titulo,
141
            'item' => $activity
142
        ]);
143
    }
144
145
    /**
146
     * @Route("/actividad/eliminar/{id}", name="admin_program_activity_delete", methods={"GET", "POST"}, requirements={"activity": "\d+"})
147
     */
148
    public function activityDeleteAction(Activity $activity, Request $request)
149
    {
150 View Code Duplication
        if ('POST' === $request->getMethod() && $request->request->has('delete')) {
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...
151
152
            // Eliminar el departamento de la base de datos
153
            $this->getDoctrine()->getManager()->remove($activity);
154
            try {
155
                $this->getDoctrine()->getManager()->flush();
156
                $this->addFlash('success', $this->get('translator')->trans('alert.deleted', [], 'activity'));
157
            } catch (\Exception $e) {
158
                $this->addFlash('error', $this->get('translator')->trans('alert.not_deleted', [], 'activity'));
159
            }
160
            return $this->redirectToRoute('admin_program_training', ['id' => $activity->getTraining()->getId()]);
161
        }
162
163
        $title = (string) $activity->getName();
164
165
        $breadcrumb = [
166
            [
167
                'fixed' => $title,
168
                'path' => 'admin_program_activity_form',
169
                'options' => ['activity' => $activity->getId()]
170
            ],
171
            ['caption' => 'menu.delete']
172
        ];
173
174
        return $this->render('activity/delete_activity.html.twig', [
175
            'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('admin_departments'),
176
            'breadcrumb' => $breadcrumb,
177
            'title' => $title,
178
            'element' => $activity
179
        ]);
180
    }
181
}
182