Completed
Push — master ( 8e9b2d...71f485 )
by Quentin
17:01 queued 12:32
created

ZoneAdminController::deleteAction()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 10
nc 3
nop 3
1
<?php
2
3
namespace Synapse\Admin\Bundle\Controller;
4
5
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
6
use Symfony\Component\HttpFoundation\RedirectResponse;
7
use Symfony\Component\HttpFoundation\Request;
8
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
9
10
/**
11
 * Controller for zones use cases action.
12
 */
13
class ZoneAdminController extends Controller
14
{
15
    /**
16
     * Component deletion action.
17
     *
18
     * @param int     $zoneId
19
     * @param int     $componentId
20
     * @param Request $request
21
     *
22
     * @return Response
23
     */
24
    public function deleteAction($zoneId, $componentId, Request $request)
25
    {
26
        if (!$zone = $this->container->get('synapse.zone.loader')->retrieve($zoneId)) {
27
            throw new NotFoundHttpException(sprintf('No zone found under id "%s"', $zoneId));
28
        }
29
        if (!$component = $this->container->get('synapse.component.loader')->retrieve($componentId)) {
30
            throw new NotFoundHttpException(sprintf('No component found under id "%s"', $componentId));
31
        }
32
33
        $this->container->get('synapse.zone.domain')->removeComponent(
34
            $zone,
35
            $component
36
        );
37
38
        return new RedirectResponse(
39
            $request->server->get('HTTP_REFERER')
40
        );
41
    }
42
}
43