MeteoconsTwigExtension::getFunctions()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
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 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\Assets;
13
14
use Twig\TwigFunction;
15
use WBW\Library\Symfony\Renderer\Assets\IconRendererInterface;
16
use WBW\Library\Types\Helper\ArrayHelper;
17
18
/**
19
 * Meteocons Twig extension.
20
 *
21
 * @author webeweb <https://github.com/webeweb>
22
 * @package WBW\Bundle\CoreBundle\Twig\Extension\Assets
23
 */
24
class MeteoconsTwigExtension extends AbstractMeteoconsTwigExtension implements IconRendererInterface {
25
26
    /**
27
     * Service name.
28
     *
29
     * @var string
30
     */
31
    const SERVICE_NAME = "wbw.core.twig.extension.assets.meteocons";
32
33
    /**
34
     * Get the Twig functions.
35
     *
36
     * @return TwigFunction[] Returns the Twig functions.
37
     */
38
    public function getFunctions(): array {
39
40
        return [
41
            new TwigFunction("meteoconsIcon", [$this, "meteoconsIconFunction"], ["is_safe" => ["html"]]),
42
        ];
43
    }
44
45
    /**
46
     * Display a Meteocons icon.
47
     *
48
     * @param array $args The arguments.
49
     * @return string Returns a Meteocons icon.
50
     */
51
    public function meteoconsIconFunction(array $args = []): string {
52
        return $this->meteoconsIcon(ArrayHelper::get($args, "name", "A"), ArrayHelper::get($args, "style"));
53
    }
54
55
    /**
56
     * {@inheritDoc}
57
     */
58
    public function renderIcon(?string $name, ?string $style): string {
59
        return $this->meteoconsIconFunction(["name" => $name, "style" => $style]);
60
    }
61
}
62