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

DeleteFormHandler::handle()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 28
Code Lines 16

Duplication

Lines 19
Ratio 67.86 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 19
loc 28
ccs 0
cts 22
cp 0
rs 8.8571
c 0
b 0
f 0
cc 3
eloc 16
nc 3
nop 2
crap 12
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