NavigationBuilder   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 42
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 12 3
A __construct() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\PropellerAdmin\Events\Listeners;
6
7
use AbterPhp\Framework\Events\NavigationReady;
8
use AbterPhp\Framework\Navigation\Navigation;
9
use AbterPhp\PropellerAdmin\Decorator\General;
10
use AbterPhp\PropellerAdmin\Decorator\Navigation\Navbar;
11
use AbterPhp\PropellerAdmin\Decorator\Navigation\Primary;
12
13
class NavigationBuilder
14
{
15
    /** @var Primary */
16
    protected $primaryDecorator;
17
18
    /** @var Navbar */
19
    protected $navbarDecorator;
20
21
    /** @var General */
22
    protected $generalDecorator;
23
24
    /**
25
     * NavigationDecorator constructor.
26
     *
27
     * @param Primary $primaryDecorator
28
     * @param Navbar  $navbarDecorator
29
     * @param General $generalDecorator
30
     */
31
    public function __construct(Primary $primaryDecorator, Navbar $navbarDecorator, General $generalDecorator)
32
    {
33
        $this->primaryDecorator = $primaryDecorator;
34
        $this->navbarDecorator  = $navbarDecorator;
35
        $this->generalDecorator = $generalDecorator;
36
    }
37
38
    /**
39
     * @param NavigationReady $event
40
     *
41
     * @throws \Opulence\Routing\Urls\URLException
42
     */
43
    public function handle(NavigationReady $event)
44
    {
45
        $navigation = $event->getNavigation();
46
47
        $nodes = array_merge([$navigation], $navigation->getExtendedDescendantNodes());
48
49
        $this->generalDecorator->init()->decorate($nodes);
50
51
        if ($navigation->hasIntent(Navigation::INTENT_PRIMARY)) {
52
            $this->primaryDecorator->init()->decorate($nodes);
53
        } elseif ($navigation->hasIntent(Navigation::INTENT_NAVBAR)) {
54
            $this->navbarDecorator->init()->decorate($nodes);
55
        }
56
    }
57
}
58