Completed
Push — master ( c0a77a...dfe684 )
by WEBEWEB
01:34
created

MeteoconsTwigExtension::renderIcon()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 2
1
<?php
2
3
/**
4
 * This file is part of the core-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\CoreBundle\Twig\Extension\Plugin;
13
14
use Twig_Environment;
15
use Twig_SimpleFunction;
16
use WBW\Bundle\CoreBundle\Renderer\IconRendererInterface;
17
use WBW\Library\Core\Argument\ArrayHelper;
18
19
/**
20
 * Meteocons Twig extension.
21
 *
22
 * @author webeweb <https://github.com/webeweb/>
23
 * @package WBW\Bundle\CoreBundle\Twig\Extension\Plugin
24
 */
25
class MeteoconsTwigExtension extends AbstractMeteoconsTwigExtension implements IconRendererInterface {
26
27
    /**
28
     * Service name.
29
     *
30
     * @var string
31
     */
32
    const SERVICE_NAME = "webeweb.core.twig.extension.plugin.meteocons";
33
34
    /**
35
     * Constructor.
36
     *
37
     * @param Twig_Environment $twigEnvironment The wig environment.
38
     */
39
    public function __construct(Twig_Environment $twigEnvironment) {
40
        parent::__construct($twigEnvironment);
41
    }
42
43
    /**
44
     * Get the Twig functions.
45
     *
46
     * @return array Returns the Twig functions.
47
     */
48
    public function getFunctions() {
49
        return [
50
            new Twig_SimpleFunction("meteoconsIcon", [$this, "meteoconsIconFunction"], ["is_safe" => ["html"]]),
51
        ];
52
    }
53
54
    /**
55
     * Displays a Meteocons icon.
56
     *
57
     * @param array $args The arguments.
58
     * @return string Returns a Meteocons icon.
59
     */
60
    public function meteoconsIconFunction(array $args = []) {
61
        return $this->meteoconsIcon(ArrayHelper::get($args, "name", "A"), ArrayHelper::get($args, "style"));
62
    }
63
64
    /**
65
     * {@inheritdoc}
66
     */
67
    public function renderIcon($name, $style) {
68
        return $this->meteoconsIconFunction(["name" => $name, "style" => $style]);
69
    }
70
71
}
72