Completed
Pull Request — dev (#50)
by
unknown
07:48
created

FormRequestController::activationAction()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 27
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 1 Features 2
Metric Value
c 3
b 1
f 2
dl 0
loc 27
rs 8.8571
cc 1
eloc 5
nc 1
nop 1
1
<?php
2
3
namespace AppBundle\Controller;
4
5
use AppBundle\Entity\FormRequest;
6
use AppBundle\Entity\DTO\Filter;
7
use AppBundle\Form\DTO\FormRequestFilterType;
8
use AppBundle\Form\FormRequestType;
9
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
10
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
11
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
12
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
13
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
14
use Symfony\Component\HttpFoundation\RedirectResponse;
15
use Symfony\Component\HttpFoundation\Request;
16
17
/**
18
 * Class FormRequestController.
19
 *
20
 * @Route("/form_request", name="form_requests")
21
 */
22
class FormRequestController extends Controller
23
{
24
    /**
25
     * @Route("", name="form_request_list")
26
     * @Template("@App/request_forms.html.twig")
27
     *
28
     * @param Request $request
29
     *
30
     * @return array
31
     */
32 View Code Duplication
    public function listAction(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...
33
    {
34
        $em = $this->getDoctrine()->getManager();
35
        $filter = new Filter();
36
        $filterForm = $this->createForm(FormRequestFilterType::class, $filter)
37
            ->add('Search', SubmitType::class);
38
39
        $filterForm->handleRequest($request);
40
        $formRequests = $this->get('knp_paginator')->paginate(
41
            $em->getRepository(FormRequest::class)->selectRequestFormsByParams($filter),
42
            $request->query->getInt('page', 1),
43
            10
44
        );
45
46
        $approveForms = [];
47
48
        foreach ($formRequests as $formRequest) {
49
            if ($formRequest->getStatus() == 'pending') {
50
                $approveForms[$formRequest->getId()] = $this->createForm(FormRequestType::class, $formRequest, [
51
                    'method' => 'PUT',
52
                    'action' => $this->generateUrl('form_approve', ['id' => $formRequest->getId()]),
53
                ])
54
                    ->createView();
55
            }
56
        }
57
58
        return [
59
            'formRequests' => $formRequests,
60
            'approveForms' => $approveForms,
61
            'filterForm' => $filterForm->createView(),
62
        ];
63
    }
64
65
    /**
66
     * @Route("/form_request/approve", name="form_approve")
67
     *
68
     * @Method("PUT")
69
     *
70
     * @param Request     $request
71
     * @param FormRequest $formRequest
0 ignored issues
show
Documentation introduced by
There is no parameter named $formRequest. 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...
72
     *
73
     */
74
    public function activationAction(Request $request)
75
    {
76
        $status = $request->request->get('status');
77
        $id = $request->request->get('id');
78
        $response = ['status' => $status, 'id' => $id];
79
        return $this->json(['response' => $response]);
80
//        $em = $this->getDoctrine()->getManager();
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
81
//        $form = $this->createForm(FormRequestType::class, $formRequest, [
82
//            'method' => 'PUT',
83
//            'action' => $this->generateUrl('form_approve', ['id' => $formRequest->getId()]),
84
//        ]);
85
//        $form->handleRequest($request);
86
//        if ($form->isSubmitted()) {
87
//            if ($form->isValid()) {
88
//                $em->persist($formRequest);
89
//                $em->flush();
90
//                $this->get('app.email_notification')->sendNotification(
91
//                    $formRequest->getUser()->getEmail(),
92
//                    'Form request action',
93
//                    'Hello, '.$formRequest->getUser()->getFirstName().'.
94
//                    Your form request was '.$formRequest->getStatus().'.'
95
//                );
96
//            }
97
//        }
98
99
//        return $this->redirect($this->generateUrl('form_request_list'));
0 ignored issues
show
Unused Code Comprehensibility introduced by
74% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
100
    }
101
}
102