AdminListSubscriber   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getSubscribedEvents() 0 6 1
A postDelete() 0 12 2
1
<?php
2
3
namespace Kunstmaan\AdminListBundle\EventSubscriber;
4
5
use Kunstmaan\AdminListBundle\Entity\OverviewNavigationInterface;
6
use Kunstmaan\NodeBundle\Event\Events;
7
use Kunstmaan\NodeBundle\Event\NodeEvent;
8
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
9
use Symfony\Component\HttpFoundation\RedirectResponse;
10
use Symfony\Component\Routing\RouterInterface;
11
12
/**
13
 * Class AdminListSubscriber.
14
 */
15
class AdminListSubscriber implements EventSubscriberInterface
16
{
17
    /**
18
     * @var RouterInterface
19
     */
20
    private $router;
21
22
    /**
23
     * ArticleSubscriber constructor.
24
     *
25
     * @param RouterInterface $router
26
     */
27
    public function __construct(RouterInterface $router)
28
    {
29
        $this->router = $router;
30
    }
31
32
    /**
33
     * @return array
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use array<*,string>.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
34
     */
35
    public static function getSubscribedEvents()
36
    {
37
        return [
38
            Events::POST_DELETE => 'postDelete',
39
        ];
40
    }
41
42
    /**
43
     * @param NodeEvent $event
44
     */
45
    public function postDelete(NodeEvent $event)
46
    {
47
        $page = $event->getPage();
48
49
        // Redirect to admin list when deleting a page that implements the OverviewNavigationInterface.
50
        if ($page instanceof OverviewNavigationInterface) {
51
            $route = $this->router->generate($page->getOverViewRoute());
52
            $response = new RedirectResponse($route);
53
54
            $event->setResponse($response);
55
        }
56
    }
57
}
58