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

MenuDirective   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 0
dl 0
loc 42
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A show() 0 6 1
A extractArguments() 0 6 1
A returnMenu() 0 8 2
A __toString() 0 4 1
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