Completed
Pull Request — master (#90)
by Arnaud
21:22
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 60%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 7
dl 10
loc 36
ccs 6
cts 10
cp 0.6
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
     * @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