AbstractBadgeTwigExtension   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 2
dl 0
loc 21
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A bootstrapBadge() 0 12 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\Component;
13
14
use WBW\Bundle\BootstrapBundle\Badge\BadgeInterface;
15
use WBW\Bundle\BootstrapBundle\Badge\BadgeRenderer;
16
use WBW\Bundle\BootstrapBundle\Twig\Extension\AbstractTwigExtension;
17
18
/**
19
 * Badge Twig extension.
20
 *
21
 * @author webeweb <https://github.com/webeweb/>
22
 * @package WBW\Bundle\BootstrapBundle\Twig\Extension\Component
23
 * @abstract
24
 */
25
abstract class AbstractBadgeTwigExtension extends AbstractTwigExtension {
26
27
    /**
28
     * Displays a Bootstrap badge.
29
     *
30
     * @param BadgeInterface $badge The badge.
31
     * @return string Returns the Bootstrap badge.
32
     */
33
    protected function bootstrapBadge(BadgeInterface $badge): string {
34
35
        $attributes = [];
36
37
        $attributes["class"]   = ["badge"];
38
        $attributes["class"][] = BadgeRenderer::renderType($badge);
39
        $attributes["class"][] = 4 === $this->getVersion() ? BadgeRenderer::renderPill($badge) : null;
40
41
        $innerHTML = BadgeRenderer::renderContent($badge);
42
43
        return static::coreHTMLElement("span", $innerHTML, $attributes);
44
    }
45
}
46