Completed
Push — master ( d58eaa...3f3d99 )
by WEBEWEB
01:38
created

AbstractBootstrapTwigExtension::bootstrapTag()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 11
rs 9.4285
cc 2
eloc 4
nc 2
nop 2
1
<?php
2
3
/**
4
 * This file is part of the bootstrap-bundle package.
5
 *
6
 * (c) 2018 NdC/WBW
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\Library\Core\Navigation\NavigationInterface;
16
use WBW\Library\Core\Utility\StringUtility;
17
18
/**
19
 * Abstract Bootstrap Twig extension.
20
 *
21
 * @author NdC/WBW <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
     * Displays a Bootstrap simple tag.
43
     *
44
     * @param string $name The tag name.
45
     * @param string $content The tag contant
46
     * @return string Returns the Bootstrap tag.
47
     */
48
    final protected function bootstrapTag($name, $content) {
49
50
        // Initialize the template.
51
        $template = "<" . $name . ">%innerHTML%</" . $name . ">";
52
53
        // Initialize the parameters.
54
        $innerHTML = null !== $content ? $content : "";
55
56
        // Return the HTML.
57
        return StringUtility::replace($template, ["%innerHTML%"], [$innerHTML]);
58
    }
59
60
}
61