Completed
Pull Request — master (#90)
by Arnaud
05:26
created

DeleteResponder   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
c 0
b 0
f 0
lcom 1
cbo 6
dl 0
loc 48
ccs 0
cts 12
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
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
use Symfony\Component\Routing\RouterInterface;
11
12
class DeleteResponder implements ResponderInterface
13
{
14
    use ResponderTrait;
15
    
16
    /**
17
     * @var RouterInterface
18
     */
19
    private $router;
20
    
21
    /**
22
     * CreateResponder constructor.
23
     *
24
     * @param RouterInterface $router
25
     */
26
    public function __construct(RouterInterface $router)
27
    {
28
        $this->router = $router;
29
    }
30
    
31
    /**
32
     * @param ActionConfiguration $configuration
33
     * @param AdminInterface      $admin
34
     * @param FormInterface       $form
35
     *
36
     * @return Response
37
     */
38
    public function respond(
39
        ActionConfiguration $configuration,
40
        AdminInterface $admin,
41
        FormInterface $form
42
    ) {
43
        $template = $configuration->getParameter('template');
44
        
45
        if ($form->isSubmitted() && $form->isValid()) {
46
            $url = $this
47
                ->router
48
                ->generate($admin->generateRouteName('list'))
49
            ;
50
51
            return new RedirectResponse($url);
52
        }
53
        
54
        return $this->render($template, [
55
            'admin' => $admin,
56
            'form' => $form->createView(),
57
        ]);
58
    }
59
}
60