Completed
Pull Request — master (#90)
by Arnaud
18:40
created

DeleteResponder   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 6
dl 0
loc 34
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A respond() 0 21 3
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 Symfony\Component\Form\FormInterface;
8
use Symfony\Component\HttpFoundation\RedirectResponse;
9
use Symfony\Component\HttpFoundation\Response;
10
11
class DeleteResponder extends AbstractResponder
12
{
13
    /**
14
     * Display the delete form (to ensure not deleting entities just with an url call) and redirect to the list Action
15
     * when the form is submitted.
16
     *
17
     * @param ActionConfiguration $configuration
18
     * @param AdminInterface      $admin
19
     * @param FormInterface       $form
20
     *
21
     * @return Response
22
     */
23 2
    public function respond(
24
        ActionConfiguration $configuration,
25
        AdminInterface $admin,
26
        FormInterface $form
27
    ) {
28 2
        $template = $configuration->getParameter('template');
29
        
30 2
        if ($form->isSubmitted() && $form->isValid()) {
31
            $url = $this
32 1
                ->router
33 1
                ->generate($admin->generateRouteName('list'))
34
            ;
35
36 1
            return new RedirectResponse($url);
37
        }
38
        
39 1
        return $this->render($template, [
40 1
            'admin' => $admin,
41 1
            'form' => $form->createView(),
42
        ]);
43
    }
44
}
45