Completed
Pull Request — dev (#24)
by
unknown
03:54
created

SurveyController::surveyCreateAction()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 19
Code Lines 12

Duplication

Lines 19
Ratio 100 %

Code Coverage

Tests 12
CRAP Score 3

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 19
loc 19
ccs 12
cts 12
cp 1
rs 9.4285
cc 3
eloc 12
nc 2
nop 2
crap 3
1
<?php
2
3
namespace AppBundle\Controller;
4
5
use AppBundle\Entity\SurveyAnswer;
6
use AppBundle\Entity\Survey;
7
use AppBundle\Entity\SurveyType;
8
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
9
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
10
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
11
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
12
use Symfony\Component\HttpFoundation\Request;
13
14
class SurveyController extends Controller
15
{
16
    /**
17
     * @Route("/surveys", name="surveys")
18
     * @Template("@App/surveys.html.twig")
19
     */
20 1
    public function surveysAction(Request $request)
21
    {
22 1
        $em = $this->getDoctrine()->getManager();
23 1
        $surveys = $em->getRepository(Survey::class)->findSurveyByStatus('submited');
24 1
        $surveyTypes = $em->getRepository(SurveyType::class)->findAll();
25 1
        $paginator = $this->get('knp_paginator');
26 1
        $pagination = $paginator->paginate($surveys, $request->query->getInt('page', 1), 10);
27
28
        return [
29 1
            'surveys' => $pagination, 'survey_types' => $surveyTypes,
30
        ];
31
    }
32
33
    /**
34
     * @param Survey $survey
35
     * @Route("/survey/{id}", name="survey_get")
36
     * @Template("@App/survey.html.twig")
37
     * @ParamConverter("survey", class="AppBundle:Survey")
38
     */
39 1
    public function surveyAction(Survey $survey)
40
    {
41 1
        $em = $this->getDoctrine()->getManager();
42 1
        $fields = $em->getRepository(SurveyAnswer::class)->findAnswersBySurvey($survey);
43
44
        return [
45 1
            'survey' => $survey, 'fields' => $fields,
46
        ];
47
    }
48
49
    /**
50
     * @param Request $request, SurveyType $surveyType
0 ignored issues
show
Documentation introduced by
There is no parameter named $request,. Did you maybe mean $request?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
51
     * @Route("/survey/create/{survey_type}", name="survey_create")
52
     * @ParamConverter("surveyType", options={"mapping": {"survey_type": "name"}})
53
     */
54 1 View Code Duplication
    public function surveyCreateAction(Request $request, SurveyType $surveyType)
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...
55
    {
56 1
        $survey = new Survey();
57 1
        $survey->setType($surveyType);
58 1
        $form = $this->createForm(\AppBundle\Form\SurveyType::class, $survey);
59 1
        $form->handleRequest($request);
60
61 1
        if ($form->isSubmitted() && $form->isValid()) {
62 1
            $em = $this->getDoctrine()->getManager();
63 1
            $em->persist($survey);
64 1
            $em->flush();
65
66 1
            return $this->redirectToRoute('homepage');
67
        }
68
69 1
        return $this->render('@App/surveyform.html.twig', array(
70 1
            'form' => $form->createView(), 'type' => $surveyType,
71
        ));
72
    }
73
74
    /**
75
     * @param Request $request, Survey $survey
0 ignored issues
show
Documentation introduced by
There is no parameter named $request,. Did you maybe mean $request?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
76
     * @Route("/survey/delete/{id}", name="survey_delete")
77
     * @ParamConverter("survey", class="AppBundle:Survey")
78
     */
79 1 View Code Duplication
    public function surveyDeleteAction(Request $request, Survey $survey)
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...
80
    {
81 1
        $surveyType = $survey->getType();
82
83 1
        $form = $this->createForm(\AppBundle\Form\SurveyType::class, $survey);
84 1
        $form->handleRequest($request);
85
86 1
        if ($form->isSubmitted() && $form->isValid()) {
87 1
            $em = $this->getDoctrine()->getManager();
88 1
            $em->remove($survey);
89 1
            $em->flush();
90
91 1
            return $this->redirectToRoute('homepage');
92
        }
93
94 1
        return $this->render('@App/surveyform.html.twig', array(
95 1
            'form' => $form->createView(), 'type' => $surveyType,
96
        ));
97
    }
98
}
99