MenuGroup   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 37
c 0
b 0
f 0
wmc 3
lcom 1
cbo 2
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A add() 0 4 1
A render() 0 20 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
}