AbstractAlertTwigExtension::bootstrapAlert()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.6666
c 0
b 0
f 0
cc 2
nc 2
nop 1
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\Alert\AlertInterface;
15
use WBW\Bundle\BootstrapBundle\Alert\AlertRenderer;
16
use WBW\Bundle\BootstrapBundle\Twig\Extension\AbstractTwigExtension;
17
18
/**
19
 * Abstract alert Twig extension.
20
 *
21
 * @author webeweb <https://github.com/webeweb/>
22
 * @package WBW\Bundle\BootstrapBundle\Twig\Extension\Component
23
 * @abstract
24
 */
25
abstract class AbstractAlertTwigExtension extends AbstractTwigExtension {
26
27
    /**
28
     * Displays a Bootstrap alert.
29
     *
30
     * @param AlertInterface $alert The alert.
31
     * @return string Returns the Bootstrap alert.
32
     */
33
    protected function bootstrapAlert(AlertInterface $alert): string {
34
35
        $span   = static::coreHTMLElement("span", "&times;", ["aria-hidden" => "true"]);
36
        $button = static::coreHTMLElement("button", $span, ["class" => "close", "type" => "button", "data-dismiss" => "alert", "aria-label" => "Close"]);
37
38
        $attributes = [];
39
40
        $attributes["class"]   = ["alert", AlertRenderer::renderType($alert)];
41
        $attributes["class"][] = AlertRenderer::renderDismissible($alert);
42
        $attributes["role"]    = ["alert"];
43
44
        $innerHTML = [
45
            (true === $alert->getDismissible() ? $button : ""),
46
            AlertRenderer::renderContent($alert),
47
        ];
48
49
        return static::coreHTMLElement("div", implode("", $innerHTML), $attributes);
50
    }
51
}
52