AbstractNavTwigExtension   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 36
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A bootstrapNav() 0 3 1
A bootstrapNavs() 0 15 3
1
<?php
2
3
/*
4
 * This file is part of the bootstrap-bundle package.
5
 *
6
 * (c) 2018 WEBEWEB
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace WBW\Bundle\BootstrapBundle\Twig\Extension\Component;
13
14
use WBW\Bundle\BootstrapBundle\Twig\Extension\AbstractTwigExtension;
15
16
/**
17
 * Abstract nav Twig extension.
18
 *
19
 * @author webeweb <https://github.com/webeweb/>
20
 * @package WBW\Bundle\BootstrapBundle\Twig\Extension\Component
21
 * @abstract
22
 */
23
abstract class AbstractNavTwigExtension extends AbstractTwigExtension {
24
25
    /**
26
     * Displays a Bootstrap nav item.
27
     *
28
     * @param string|null $item The item.
29
     * @return string Returns the Bootstrap nav item.
30
     */
31
    private function bootstrapNav(?string $item): string {
32
        return static::coreHTMLElement("li", $item, ["role" => "presentation"]);
33
    }
34
35
    /**
36
     * Displays a Bootstrap navs.
37
     *
38
     * @param array $items The items.
39
     * @param string|null $class The class.
40
     * @param bool|null $stacked Stacked ?
41
     * @return string Returns the Bootstrap nav.
42
     */
43
    protected function bootstrapNavs(array $items, ?string $class, ?bool $stacked): string {
44
45
        $attributes = [];
46
47
        $attributes["class"][] = "nav";
48
        $attributes["class"][] = $class;
49
        $attributes["class"][] = true === $stacked ? "nav-stacked" : null;
50
51
        $innerHTML = [];
52
        foreach ($items as $current) {
53
            $innerHTML[] = $this->bootstrapNav($current);
54
        }
55
56
        return static::coreHTMLElement("ul", "\n" . implode("\n", $innerHTML) . "\n", $attributes);
57
    }
58
}
59