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

DeleteResponder   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 27.78 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A respond() 10 23 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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 2
     * @param FormInterface       $form
21
     *
22
     * @return Response
23
     */
24
    public function respond(
25 2
        ActionConfiguration $configuration,
26
        AdminInterface $admin,
27 2
        FormInterface $form
28
    ) {
29 1
        $template = $configuration->getParameter('template');
30 1
        
31 View Code Duplication
        if ($form->isSubmitted() && $form->isValid()) {
32
            $generator = new RouteNameGenerator();
33 1
    
34
            $url = $this
35
                ->router
36 1
                ->generate($generator->generate('list', $admin->getName(), $admin->getConfiguration()))
37 1
            ;
38 1
39
            return new RedirectResponse($url);
40
        }
41
        
42
        return $this->render($template, [
43
            'admin' => $admin,
44
            'form' => $form->createView(),
45
        ]);
46
    }
47
}
48