Completed
Push — master ( a6bf95...b748b6 )
by WEBEWEB
18:04
created

RendererTwigExtension::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
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;
13
14
use Twig_Environment;
15
use WBW\Bundle\BootstrapBundle\Twig\Extension\Component\GlyphiconTwigExtension;
16
use WBW\Bundle\CoreBundle\Twig\Extension\RendererTwigExtension as BaseTwigExtension;
17
18
/**
19
 * Renderer Twig extension.
20
 *
21
 * @author webeweb <https://github.com/webeweb/>
22
 * @package WBW\Bundle\BootstrapBundle\Twig\Extension
23
 */
24
class RendererTwigExtension extends BaseTwigExtension {
25
26
    /**
27
     * Service name.
28
     *
29
     * @var string
30
     */
31
    const SERVICE_NAME = "webeweb.bootstrap.twig.extension.renderer";
32
33
    /**
34
     * Constructor.
35
     *
36
     * @param Twig_Environment $twigEnvironment The twig environment.
37
     */
38
    protected function __construct(Twig_Environment $twigEnvironment) {
39
        parent::__construct($twigEnvironment);
40
    }
41
42
    /**
43
     * Render an icon.
44
     *
45
     * @param Twig_Environment $twigEnvironment The twig environment.
46
     * @param string $name The icon name.
47
     * @param string $style The icon style.
48
     * @return string Returns a rendered icon.
49
     */
50
    public static function renderIcon(Twig_Environment $twigEnvironment, $name, $style = null) {
51
52
        // Determines the handler.
53
        $handler = explode(":", $name);
54
55
        // Get and check the parse count.
56
        $parseNb = count($handler);
57
        if ($parseNb < 1 || 2 < $parseNb) {
58
            return "";
59
        }
60
        if (1 === count($handler)) {
61
            $handler = ["g", $name];
62
        }
63
64
        // Initialize the output.
65
        $output = "";
0 ignored issues
show
Unused Code introduced by
$output is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
66
67
        // Swith into handler.
68
        switch ($handler[0]) {
69
70
            case "b": // Bootstrap
71
            case "g": // Glyphicon
72
                $output = (new GlyphiconTwigExtension($twigEnvironment))->renderIcon($handler[1], $style);
73
                break;
74
75
            default:
76
                $output = parent::renderIcon($twigEnvironment, $name, $style);
77
                break;
78
        }
79
80
        // Return the output.
81
        return $output;
82
    }
83
84
}
85