Passed
Push — release/3.x ( b848c9...b5378b )
by
unknown
08:07 queued 10s
created

buildAndForwardEvent()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 35
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
cc 4
eloc 21
nc 4
nop 1
dl 0
loc 35
ccs 0
cts 30
cp 0
crap 20
rs 8.5806
c 0
b 0
f 0
1
<?php
2
/**
3
 * @copyright Zicht Online <http://zicht.nl>
4
 */
5
6
namespace Zicht\Bundle\PageBundle\AdminMenu;
7
8
use Symfony\Component\EventDispatcher\Event;
9
use Symfony\Component\Routing\Router;
10
use Zicht\Bundle\AdminBundle\Event\AdminEvents;
11
use Zicht\Bundle\AdminBundle\Event\MenuEvent;
12
use Zicht\Bundle\AdminBundle\Event\PropagationInterface;
13
use Zicht\Bundle\PageBundle\Entity\Page;
14
use Zicht\Bundle\PageBundle\Event\PageViewEvent;
15
16
/**
17
 * Add links to see zz translations to the zicht admin menu
18
 */
19
class TranslatePageEventPropagationBuilder implements PropagationInterface
20
{
21
    /** @var Router */
22
    private $router;
23
24
    /**
25
     * @param Router $router
26
     */
27
    public function __construct(Router $router)
28
    {
29
        $this->router = $router;
30
    }
31
32
    /**
33
     * Build the relevant event and forward it.
34
     *
35
     * @param \Symfony\Component\EventDispatcher\Event $event
36
     * @return mixed|void
37
     */
38
    public function buildAndForwardEvent(Event $event)
39
    {
40
        if (!$event instanceof PageViewEvent) {
41
            return;
42
        }
43
44
        if (!$this->router) {
45
            return;
46
        }
47
48
        /** @var Page $page */
49
        $page = $event->getPage();
50
        if (!$page->getId()) {
51
            return;
52
        }
53
54
        $event->getDispatcher()->dispatch(
0 ignored issues
show
Deprecated Code introduced by
The function Symfony\Component\EventD...\Event::getDispatcher() has been deprecated: since version 2.4, to be removed in 3.0. The event dispatcher is passed to the listener call. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

54
        /** @scrutinizer ignore-deprecated */ $event->getDispatcher()->dispatch(

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
55
            AdminEvents::MENU_EVENT,
56
            new MenuEvent(
57
                $this->router->generate('zicht_page_page_view', [
58
                    'id' => $page->getId(),
59
                    '_locale' => 'zz',
60
                ]),
61
                'Vertalingen'
62
            )
63
        );
64
65
        $event->getDispatcher()->dispatch(
0 ignored issues
show
Deprecated Code introduced by
The function Symfony\Component\EventD...\Event::getDispatcher() has been deprecated: since version 2.4, to be removed in 3.0. The event dispatcher is passed to the listener call. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

65
        /** @scrutinizer ignore-deprecated */ $event->getDispatcher()->dispatch(

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
66
            AdminEvents::MENU_EVENT,
67
            new MenuEvent(
68
                $this->router->generate('zicht_page_page_view', [
69
                    'id' => $page->getId(),
70
                    '_locale' => $page->getLanguage(),
0 ignored issues
show
Bug introduced by
Are you sure the usage of $page->getLanguage() targeting Zicht\Bundle\PageBundle\Entity\Page::getLanguage() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
71
                ]),
72
                'Pagina herladen'
73
            )
74
        );
75
    }
76
}
77