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 ( ea63f9...3c014b )
by Luis Ramón
04:34
created

LearningOutcomeController   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 128
Duplicated Lines 59.38 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 11
c 1
b 0
f 0
lcom 1
cbo 8
dl 76
loc 128
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
B groupIndexAction() 30 30 1
A formNewLearningOutcomeAction() 0 8 1
B formLearningOutcomeAction() 12 37 5
B learningOutcomeDeleteAction() 34 34 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\LearningOutcome;
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 LearningOutcomeController extends Controller
36
{
37
    /**
38
     * @Route("/{id}", name="admin_program_training_learning_outcomes", methods={"GET"})
39
     */
40 View Code Duplication
    public function groupIndexAction(Training $training, Request $request)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
41
    {
42
        /** @var EntityManager $em */
43
        $em = $this->getDoctrine()->getManager();
44
45
        $usersQuery = $em->createQuery('SELECT l FROM AppBundle:LearningOutcome l WHERE l.training = :training')
46
            ->setParameter('training', $training);
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' => 'l.code',
55
                'defaultSortDirection' => 'asc'
56
            ]
57
        );
58
59
        return $this->render('activity/manage_learning_outcomes.html.twig',
60
            [
61
                'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('admin_program'),
62
                'breadcrumb' => [
63
                    ['fixed' => $training->getName()],
64
                ],
65
                'title' => $training->getName(),
66
                'pagination' => $pagination,
67
                'training' => $training
68
            ]);
69
    }
70
71
    /**
72
     * @Route("/resultado/nuevo/{training}", name="admin_program_learning_outcome_new", methods={"GET", "POST"}, requirements={"training": "\d+"})
73
     */
74
    public function formNewLearningOutcomeAction(Training $training, Request $request)
75
    {
76
        $learningOutcome = new LearningOutcome();
77
        $learningOutcome->setTraining($training);
78
        $this->getDoctrine()->getManager()->persist($learningOutcome);
79
80
        return $this->formLearningOutcomeAction($learningOutcome, $request);
81
    }
82
83
    /**
84
     * @Route("/resultado/{id}", name="admin_program_learning_outcome_form", methods={"GET", "POST"}, requirements={"id": "\d+"})
85
     */
86
    public function formLearningOutcomeAction(LearningOutcome $learningOutcome, Request $request)
87
    {
88
        $em = $this->getDoctrine()->getManager();
89
90
        $form = $this->createForm('AppBundle\Form\Type\LearningOutcomeType', $learningOutcome, [
91
            'fixed' => true
92
        ]);
93
94
        $form->handleRequest($request);
95
96 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...
97
98
            // Guardar el usuario en la base de datos
99
            // Probar a guardar los cambios
100
            try {
101
                $em->flush();
102
                $this->addFlash('success', $this->get('translator')->trans('alert.saved', [], 'activity'));
103
                return $this->redirectToRoute('admin_program_training_learning_outcomes', ['id' => $learningOutcome->getTraining()->getId()]);
104
            } catch (\Exception $e) {
105
                $this->addFlash('error', $this->get('translator')->trans('alert.not_saved', [], 'activity'));
106
            }
107
        }
108
109
        $titulo = $learningOutcome->getId() ? (string) $learningOutcome : $this->get('translator')->trans('form.learning_outcome.new', [], 'activity');
110
111
        return $this->render('activity/form_learning_outcome.html.twig', [
112
            'form' => $form->createView(),
113
            'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('admin_program'),
114
            'breadcrumb' => [
115
                ['fixed' => $learningOutcome->getTraining()->getName(), 'path' => 'admin_program_training_learning_outcomes', 'options' => ['id' => $learningOutcome->getTraining()->getId()]],
116
                ['fixed' => $titulo]
117
            ],
118
            'new' => ($learningOutcome->getId() == 0),
119
            'title' => $titulo,
120
            'item' => $learningOutcome
121
        ]);
122
    }
123
124
125
    /**
126
     * @Route("/resultado/eliminar/{id}", name="admin_program_learning_outcome_delete", methods={"GET", "POST"}, requirements={"id": "\d+"})
127
     */
128 View Code Duplication
    public function learningOutcomeDeleteAction(LearningOutcome $learningOutcome, Request $request)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
129
    {
130
        if ('POST' === $request->getMethod() && $request->request->has('delete')) {
131
132
            // Eliminar el resultado de aprendizaje de la base de datos
133
            $this->getDoctrine()->getManager()->remove($learningOutcome);
134
            try {
135
                $this->getDoctrine()->getManager()->flush();
136
                $this->addFlash('success', $this->get('translator')->trans('alert.learning_outcome.deleted', [], 'activity'));
137
            } catch (\Exception $e) {
138
                $this->addFlash('error', $this->get('translator')->trans('alert.learning_outcome.not_deleted', [], 'activity'));
139
            }
140
            return $this->redirectToRoute('admin_program_training_learning_outcomes', ['id' => $learningOutcome->getTraining()->getId()]);
141
        }
142
143
        $title = (string) $learningOutcome->getName();
144
145
        $breadcrumb = [
146
            ['fixed' => $learningOutcome->getTraining()->getName(), 'path' => 'admin_program_training_learning_outcomes', 'options' => ['id' => $learningOutcome->getTraining()->getId()]],
147
            [
148
                'fixed' => $title,
149
                'path' => 'admin_program_learning_outcome_form',
150
                'options' => ['id' => $learningOutcome->getId()]
151
            ],
152
            ['caption' => 'menu.delete']
153
        ];
154
155
        return $this->render('activity/delete_learning_outcome.html.twig', [
156
            'menu_item' => $this->get('app.menu_builders_chain')->getMenuItemByRouteName('admin_program'),
157
            'breadcrumb' => $breadcrumb,
158
            'title' => $title,
159
            'element' => $learningOutcome
160
        ]);
161
    }
162
}
163