Completed
Push — master ( 4b2196...fd21a5 )
by WEBEWEB
01:41
created

AbstractTwigExtension::materialDesignColor()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.7666
c 0
b 0
f 0
cc 3
nc 3
nop 2
1
<?php
2
3
/*
4
 * This file is part of the adminbsb-material-design-bundle package.
5
 *
6
 * (c) 2017 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\AdminBSBBundle\Twig\Extension;
13
14
use Twig_Environment;
15
use WBW\Bundle\AdminBSBBundle\Provider\Color\DefaultColorProvider;
16
use WBW\Bundle\CoreBundle\Helper\ColorHelper;
17
use WBW\Bundle\CoreBundle\Twig\Extension\AbstractTwigExtension as BaseTwigExtension;
18
19
/**
20
 * Abstract Twig extension.
21
 *
22
 * @author webeweb <https://github.com/webeweb/>
23
 * @package WBW\Bundle\AdminBSBBundle\Twig\Extension
24
 * @abstract
25
 */
26
abstract class AbstractTwigExtension extends BaseTwigExtension {
27
28
    /**
29
     * Constructor.
30
     *
31
     * @param Twig_Environment $twigEnvironment The Twig environment.
32
     */
33
    public function __construct(Twig_Environment $twigEnvironment) {
34
        parent::__construct($twigEnvironment);
35
    }
36
37
    /**
38
     * Material Design color.
39
     *
40
     * @param string $name The name.
41
     * @param string $prefix The prefix.
42
     * @return string Returns the Material Design color.
43
     */
44
    public static function materialDesignColor($name, $prefix = "") {
45
46
        $colors = ColorHelper::getMaterialDesignColorPalette();
47
48
        $color = $colors[0];
49
50
        foreach ($colors as $current) {
51
            if ($name !== $current->getName()) {
52
                continue;
53
            }
54
            $color = $current;
55
        }
56
57
        return implode("", [$prefix, $color->getName()]);
58
    }
59
}
60