AbstractTwigExtension   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 3
dl 0
loc 34
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A materialDesignColor() 0 15 3
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\CoreBundle\Helper\ColorHelper;
16
use WBW\Bundle\CoreBundle\Twig\Extension\AbstractTwigExtension as BaseTwigExtension;
17
18
/**
19
 * Abstract Twig extension.
20
 *
21
 * @author webeweb <https://github.com/webeweb/>
22
 * @package WBW\Bundle\AdminBSBBundle\Twig\Extension
23
 * @abstract
24
 */
25
abstract class AbstractTwigExtension extends BaseTwigExtension {
26
27
    /**
28
     * Constructor.
29
     *
30
     * @param Environment $twigEnvironment The Twig environment.
31
     */
32
    public function __construct(Environment $twigEnvironment) {
33
        parent::__construct($twigEnvironment);
34
    }
35
36
    /**
37
     * Material Design color.
38
     *
39
     * @param string|null $name The name.
40
     * @param string $prefix The prefix.
41
     * @return string Returns the Material Design color.
42
     */
43
    public static function materialDesignColor(?string $name, string $prefix = ""): string {
44
45
        $colors = ColorHelper::getMaterialDesignColorPalette();
46
47
        $color = $colors[0];
48
49
        foreach ($colors as $current) {
50
            if ($name !== $current->getName()) {
51
                continue;
52
            }
53
            $color = $current;
54
        }
55
56
        return implode("", [$prefix, $color->getName()]);
57
    }
58
}
59