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

DeleteFormHandler   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 52
Duplicated Lines 36.54 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 5
dl 19
loc 52
ccs 0
cts 26
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B handle() 19 28 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\Form\Handler;
4
5
use LAG\AdminBundle\Admin\AdminInterface;
6
use Symfony\Bundle\FrameworkBundle\Routing\Router;
7
use Symfony\Component\Form\FormInterface;
8
use Symfony\Component\HttpFoundation\RedirectResponse;
9
10
class DeleteFormHandler implements FormHandlerInterface
11
{
12
    /**
13
     * @var Router
14
     */
15
    private $router;
16
    
17
    /**
18
     * DeleteFormHandler constructor.
19
     *
20
     * @param Router $router
21
     */
22
    public function __construct(Router $router)
23
    {
24
        $this->router = $router;
25
    }
26
    
27
    /**
28
     * @param FormInterface $form
29
     * @param AdminInterface $admin
30
     *
31
     * @return RedirectResponse
32
     */
33
    public function handle(FormInterface $form, AdminInterface $admin)
34
    {
35 View Code Duplication
        if ($form->isValid()) {
0 ignored issues
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...
36
            // remove the current entity
37
            $admin->remove();
38
            
39
            // redirect to list if the action exist
40
            $allowedActions = $admin
41
                ->getConfiguration()
42
                ->getParameter('actions')
43
            ;
44
    
45
            if (array_key_exists('list', $allowedActions)) {
46
                $url = $this
47
                    ->router
48
                    ->generate($admin->generateRouteName('list'));
49
                
50
                return new RedirectResponse($url);
51
            }
52
            return new RedirectResponse('/');
53
        }
54
        $url = $this
55
            ->router
56
            ->generate($admin->generateRouteName('delete'))
57
        ;
58
        
59
        return new RedirectResponse($url);
60
    }
61
}
62