Completed
Push — 2.0 ( f56b08...046d46 )
by Nicolas
02:09
created

MenuDirective::returnMenu()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 2
eloc 4
nc 2
nop 0
1
<?php
2
3
namespace Modules\Menu\Blade;
4
5
final class MenuDirective
6
{
7
    private $name;
8
    private $presenter;
9
    private $bindings;
10
11
    public function show($arguments)
12
    {
13
        $this->extractArguments($arguments);
14
15
        return $this->returnMenu();
16
    }
17
18
    /**
19
     * Extract the possible arguments as class properties
20
     * @param array $arguments
21
     */
22
    private function extractArguments(array $arguments)
23
    {
24
        $this->name = array_get($arguments, 0);
25
        $this->presenter = array_get($arguments, 1);
26
        $this->bindings = array_get($arguments, 2, []);
27
    }
28
29
    /**
30
     * Prepare arguments and return menu
31
     * @return string|null
32
     */
33
    private function returnMenu()
34
    {
35
        if ($this->presenter === null) {
36
            $this->presenter = config('asgard.menu.config.default_menu_presenter');
37
        }
38
39
        return app('menus')->get($this->name, $this->presenter, $this->bindings);
40
    }
41
42
    public function __toString()
43
    {
44
        return $this->returnMenu();
45
    }
46
}
47