Menu::render()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 34
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 34
c 0
b 0
f 0
rs 8.8571
cc 1
eloc 23
nc 1
nop 0
1
<?php
2
namespace rtens\domin\delivery\web\menu;
3
4
use rtens\domin\delivery\web\Element;
5
6
class Menu {
7
8
    /** @var MenuItem[] */
9
    private $left = [];
10
11
    /** @var MenuItem[] */
12
    private $right = [];
13
14
    /** @var string */
15
    private $brand = 'domin';
16
17
    public function add(MenuItem $item) {
18
        $this->left[] = $item;
19
        return $this;
20
    }
21
22
    public function addRight(MenuItem $item) {
23
        $this->right[] = $item;
24
        return $this;
25
    }
26
27
    /**
28
     * @param string $brand Displayed on the very left of the menu
29
     * @return Menu
30
     */
31
    public function setBrand($brand) {
32
        $this->brand = $brand;
33
        return $this;
34
    }
35
36
    public function render() {
37
        $render = function (MenuItem $item) {
38
            return $item->render();
39
        };
40
41
        return new Element('nav', ['class' => 'navbar navbar-default'], [
42
            new Element('div', ['class' => 'container-fluid'], [
43
                new Element('div', ['class' => 'navbar-header'], [
44
                    new Element('button', [
45
                        'type' => 'button',
46
                        'class' => 'navbar-toggle collapsed',
47
                        'data-toggle' => 'collapse',
48
                        'data-target' => '#navbar',
49
                        'aria-expanded' => 'false',
50
                        'aria-controls' => 'navbar'
51
                    ], [
52
                        new Element('span', ['class' => 'sr-only'], ['Toggle navigation']),
53
                        new Element('span', ['class' => 'icon-bar']),
54
                        new Element('span', ['class' => 'icon-bar']),
55
                        new Element('span', ['class' => 'icon-bar']),
56
                    ]),
57
                    new Element('a', ['class' => 'navbar-brand', 'href' => '.'], [$this->brand])
58
                ]),
59
                new Element('div', ['id' => 'navbar', 'class' => 'navbar-collapse collapse'], [
60
                    new Element('ul', ['class' => 'nav navbar-nav'],
61
                        array_map($render, $this->left)
62
                    ),
63
                    new Element('ul', ['class' => 'nav navbar-nav navbar-right'],
64
                        array_map($render, $this->right)
65
                    )
66
                ])
67
            ])
68
        ]);
69
    }
70
}