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 — develop ( f94ec5...dbe70a )
by Luis Ramón
04:42
created

CriterionController   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 132
Duplicated Lines 9.09 %

Coupling/Cohesion

Components 1
Dependencies 10

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 11
c 1
b 0
f 0
lcom 1
cbo 10
dl 12
loc 132
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
B criteriaIndexAction() 0 32 1
A formNewCriterionAction() 0 8 1
B formCriterionAction() 12 40 5
B learningOutcomeDeleteAction() 0 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\Criterion;
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_ADMIN')")
34
 */
35
class CriterionController extends Controller
36
{
37
    /**
38
     * @Route("/criterios/{id}", name="admin_program_criteria", methods={"GET"})
39
     */
40
    public function criteriaIndexAction(Activity $activity, Request $request)
41
    {
42
        /** @var EntityManager $em */
43
        $em = $this->getDoctrine()->getManager();
44
45
        $usersQuery = $em->createQuery('SELECT c FROM AppBundle:Criterion c WHERE c.activity = :activity')
46
            ->setParameter('activity', $activity);
47
48
        $paginator  = $this->get('knp_paginator');
49
        $pagination = $paginator->paginate(
50
            $usersQuery,
51
            $request->query->getInt('page', 1),
52
            $this->getParameter('page.size'),
53
            [
54
                'defaultSortFieldName' => 'c.code',
55
                'defaultSortDirection' => 'asc'
56
            ]
57
        );
58
59
        return $this->render('activity/manage_criteria.html.twig',
60
            [
61
                'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('admin_program'),
62
                'breadcrumb' => [
63
                    ['fixed' => $activity->getLearningOutcome()->getTraining()->getName(), 'path' => 'admin_program_training_learning_outcomes', 'options' => ['id' => $activity->getLearningOutcome()->getTraining()->getId()]],
64
                    ['fixed' => (string) $activity->getLearningOutcome(), 'path' => 'admin_program_activities', 'options' => ['id' => $activity->getLearningOutcome()->getId()]],
65
                    ['fixed' => (string) $activity],
66
                ],
67
                'title' => $activity->getName(),
68
                'pagination' => $pagination,
69
                'activity' => $activity
70
            ]);
71
    }
72
73
    /**
74
     * @Route("/criterio/nuevo/{activity}", name="admin_program_criterion_new", methods={"GET", "POST"}, requirements={"activity": "\d+"})
75
     */
76
    public function formNewCriterionAction(Activity $activity, Request $request)
77
    {
78
        $criterion = new Criterion();
79
        $criterion->setActivity($activity);
80
        $this->getDoctrine()->getManager()->persist($criterion);
81
82
        return $this->formCriterionAction($criterion, $request);
83
    }
84
85
    /**
86
     * @Route("/criterio/{id}", name="admin_program_criterion_form", methods={"GET", "POST"}, requirements={"id": "\d+"})
87
     */
88
    public function formCriterionAction(Criterion $criterion, Request $request)
89
    {
90
        $em = $this->getDoctrine()->getManager();
91
92
        $form = $this->createForm('AppBundle\Form\Type\CriterionType', $criterion, [
93
            'fixed' => true
94
        ]);
95
96
        $form->handleRequest($request);
97
98 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...
99
100
            // Guardar el criterio de evaluación en la base de datos
101
            // Probar a guardar los cambios
102
            try {
103
                $em->flush();
104
                $this->addFlash('success', $this->get('translator')->trans('alert.saved', [], 'activity'));
105
                return $this->redirectToRoute('admin_program_criteria', ['id' => $criterion->getActivity()->getId()]);
106
            } catch (\Exception $e) {
107
                $this->addFlash('error', $this->get('translator')->trans('alert.not_saved', [], 'activity'));
108
            }
109
        }
110
111
        $title = $criterion->getId() ? (string) $criterion : $this->get('translator')->trans('form.criterion.new', [], 'activity');
112
113
        $training = $criterion->getActivity()->getLearningOutcome()->getTraining();
114
        return $this->render('activity/form_criterion.html.twig', [
115
            'form' => $form->createView(),
116
            'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('admin_program'),
117
            'breadcrumb' => [
118
                ['fixed' => $training->getName(), 'path' => 'admin_program_training_learning_outcomes', 'options' => ['id' => $training->getId()]],
119
                ['fixed' => (string) $criterion->getActivity()->getLearningOutcome(), 'path' => 'admin_program_activities', 'options' => ['id' => $criterion->getActivity()->getLearningOutcome()->getId()]],
120
                ['fixed' => (string) $criterion->getActivity(), 'path' => 'admin_program_activities', 'options' => ['id' => $criterion->getActivity()->getId()]],
121
                ['fixed' => $title]
122
            ],
123
            'new' => ($criterion->getId() == 0),
124
            'title' => $title,
125
            'item' => $criterion
126
        ]);
127
    }
128
129
130
    /**
131
     * @Route("/criterio/eliminar/{id}", name="admin_program_criterion_delete", methods={"GET", "POST"}, requirements={"id": "\d+"})
132
     */
133
    public function learningOutcomeDeleteAction(Criterion $criterion, Request $request)
134
    {
135
        if ('POST' === $request->getMethod() && $request->request->has('delete')) {
136
137
            // Eliminar el criterio de la base de datos
138
            $this->getDoctrine()->getManager()->remove($criterion);
139
            try {
140
                $this->getDoctrine()->getManager()->flush();
141
                $this->addFlash('success', $this->get('translator')->trans('alert.criterion.deleted', [], 'activity'));
142
            } catch (\Exception $e) {
143
                $this->addFlash('error', $this->get('translator')->trans('alert.criterion.not_deleted', [], 'activity'));
144
            }
145
            return $this->redirectToRoute('admin_program_criteria', ['id' => $criterion->getActivity()->getId()]);
146
        }
147
148
        $title = (string) $criterion->getName();
149
150
        $training = $criterion->getActivity()->getLearningOutcome()->getTraining();
151
        $breadcrumb = [
152
            ['fixed' => $training->getName(), 'path' => 'admin_program_training_learning_outcomes', 'options' => ['id' => $training->getId()]],
153
            ['fixed' => (string) $criterion->getActivity()->getLearningOutcome(), 'path' => 'admin_program_activities', 'options' => ['id' => $criterion->getActivity()->getLearningOutcome()->getId()]],
154
            ['fixed' => (string) $criterion->getActivity(), 'path' => 'admin_program_activities', 'options' => ['id' => $criterion->getActivity()->getId()]],
155
            ['fixed' => (string) $criterion, 'path' => 'admin_program_criterion_form', 'options' => ['id' => $criterion->getId()]],
156
            ['caption' => 'menu.delete']
157
        ];
158
159
        return $this->render('activity/delete_criterion.html.twig', [
160
            'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('admin_program'),
161
            'breadcrumb' => $breadcrumb,
162
            'title' => $title,
163
            'element' => $criterion
164
        ]);
165
    }
166
}
167