MenuGroup::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
namespace rtens\domin\delivery\web\menu;
3
4
use rtens\domin\delivery\web\Element;
5
6
class MenuGroup implements MenuItem {
7
8
    private $caption;
9
10
    /** @var MenuItem[] */
11
    private $items = [];
12
13
    public function __construct($caption) {
14
        $this->caption = $caption;
15
    }
16
17
    public function add(MenuItem $item) {
18
        $this->items[] = $item;
19
        return $this;
20
    }
21
22
    public function render() {
23
        return new Element('li', ['class' => 'dropdown'], [
24
            new Element('a', [
25
                'href' => '#',
26
                'class' => 'dropdown-toggle',
27
                'data-toggle' => 'dropdown',
28
                'role' => 'button',
29
                'aria-haspopup' => 'true',
30
                'aria-expanded' => 'false'
31
            ], [
32
                $this->caption,
33
                new Element('span', ['class' => 'caret'])
34
            ]),
35
            new Element('ul', ['class' => 'dropdown-menu'],
36
                array_map(function (MenuItem $item) {
37
                    return $item->render();
38
                }, $this->items)
39
            )
40
        ]);
41
    }
42
}