Completed
Pull Request — master (#90)
by Arnaud
19:49
created

DeleteResponder::respond()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 23
Code Lines 14

Duplication

Lines 10
Ratio 43.48 %

Code Coverage

Tests 6
CRAP Score 3.576

Importance

Changes 0
Metric Value
dl 10
loc 23
ccs 6
cts 10
cp 0.6
rs 9.0856
c 0
b 0
f 0
cc 3
eloc 14
nc 2
nop 3
crap 3.576
1
<?php
2
3
namespace LAG\AdminBundle\Action\Responder;
4
5
use LAG\AdminBundle\Action\Configuration\ActionConfiguration;
6
use LAG\AdminBundle\Admin\AdminInterface;
7
use LAG\AdminBundle\Routing\RouteNameGenerator;
8
use Symfony\Component\Form\FormInterface;
9
use Symfony\Component\HttpFoundation\RedirectResponse;
10
use Symfony\Component\HttpFoundation\Response;
11
12
class DeleteResponder extends AbstractResponder
13
{
14
    /**
15
     * Display the delete form (to ensure not deleting entities just with an url call) and redirect to the list Action
16
     * when the form is submitted.
17
     *
18
     * @param ActionConfiguration $configuration
19
     * @param AdminInterface      $admin
20
     * @param FormInterface       $form
21
     *
22
     * @return Response
23
     */
24 1
    public function respond(
25
        ActionConfiguration $configuration,
26
        AdminInterface $admin,
27
        FormInterface $form
28
    ) {
29 1
        $template = $configuration->getParameter('template');
30
        
31 1 View Code Duplication
        if ($form->isSubmitted() && $form->isValid()) {
1 ignored issue
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...
32
            $generator = new RouteNameGenerator();
33
    
34
            $url = $this
35
                ->router
36
                ->generate($generator->generate('list', $admin->getName(), $admin->getConfiguration()))
37
            ;
38
39
            return new RedirectResponse($url);
40
        }
41
        
42 1
        return $this->render($template, [
43 1
            'admin' => $admin,
44 1
            'form' => $form->createView(),
45
        ]);
46
    }
47
}
48