Completed
Push — master ( 67c65c...9a618a )
by WEBEWEB
06:47
created

AbstractBootstrapTwigExtension   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 3
c 2
b 0
f 0
lcom 0
cbo 2
dl 0
loc 43
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A bootstrapSimpleTag() 0 11 2
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;
13
14
use Twig_Extension;
15
use WBW\Bundle\BootstrapBundle\Navigation\NavigationInterface;
16
use WBW\Library\Core\Utility\StringUtility;
17
18
/**
19
 * Abstract Bootstrap Twig extension.
20
 *
21
 * @author webeweb <https://github.com/webeweb/>
22
 * @package WBW\Bundle\BootstrapBundle\Twig\Extension
23
 * @abstract
24
 */
25
abstract class AbstractBootstrapTwigExtension extends Twig_Extension {
26
27
    /**
28
     * Default content.
29
     *
30
     * @var string
31
     */
32
    const DEFAULT_CONTENT = "&nbsp;";
33
34
    /**
35
     * Default href.
36
     *
37
     * @var string
38
     */
39
    const DEFAULT_HREF = NavigationInterface::DEFAULT_HREF;
40
41
    /**
42
     * Constructor.
43
     */
44
    protected function __construct() {
45
        // NOTHING TO DO.
46
    }
47
48
    /**
49
     * Displays a Bootstrap simple tag.
50
     *
51
     * @param string $name The tag name.
52
     * @param string $content The tag content
53
     * @return string Returns the Bootstrap tag.
54
     */
55
    final protected function bootstrapSimpleTag($name, $content) {
56
57
        // Initialize the template.
58
        $template = "<" . $name . ">%innerHTML%</" . $name . ">";
59
60
        // Initialize the parameters.
61
        $innerHTML = null !== $content ? $content : "";
62
63
        // Return the HTML.
64
        return StringUtility::replace($template, ["%innerHTML%"], [$innerHTML]);
65
    }
66
67
}
68