Completed
Push — master ( 045f74...468866 )
by WEBEWEB
02:14
created

RendererTwigExtension::getFilters()   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 0
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 Twig\TwigFilter;
16
use WBW\Bundle\BootstrapBundle\Twig\Extension\Component\GlyphiconTwigExtension;
17
use WBW\Bundle\CoreBundle\Twig\Extension\RendererTwigExtension as BaseTwigExtension;
18
19
/**
20
 * Renderer Twig extension.
21
 *
22
 * @author webeweb <https://github.com/webeweb/>
23
 * @package WBW\Bundle\BootstrapBundle\Twig\Extension
24
 */
25
class RendererTwigExtension extends BaseTwigExtension {
26
27
    /**
28
     * Service name.
29
     *
30
     * @var string
31
     */
32
    const SERVICE_NAME = "webeweb.bootstrap.twig.extension.renderer";
33
34
    /**
35
     * Get the Twig filters.
36
     *
37
     * @return TwigFilter[] Returns the Twig filters.
38
     */
39
    public function getFilters() {
40
        return [];
41
    }
42
43
    /**
44
     * Render an icon.
45
     *
46
     * @param Environment $twigEnvironment The twig environment.
47
     * @param string $name The icon name.
48
     * @param string $style The icon style.
49
     * @return string Returns a rendered icon.
50
     */
51
    public static function renderIcon(Environment $twigEnvironment, $name, $style = null) {
52
53
        // Determines the handler.
54
        $handler = explode(":", $name);
55
        if (1 === count($handler)) {
56
            array_unshift($handler, "g");
57
        }
58
        if (2 !== count($handler)) {
59
            return "";
60
        }
61
62
        // Swith into handler.
63
        switch ($handler[0]) {
64
65
            case "b": // Bootstrap
66
            case "g": // Glyphicon
67
                $output = (new GlyphiconTwigExtension($twigEnvironment))->renderIcon($handler[1], $style);
68
                break;
69
70
            default:
71
                $output = parent::renderIcon($twigEnvironment, $name, $style);
0 ignored issues
show
Compatibility introduced by
$twigEnvironment of type object<Twig\Environment> is not a sub-type of object<Twig_Environment>. It seems like you assume a child class of the class Twig\Environment to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
72
                break;
73
        }
74
75
        // Return the output.
76
        return $output;
77
    }
78
}
79