Completed
Push — master ( cc60cc...bc413d )
by WEBEWEB
01:27
created

AbstractTwigExtension   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 26
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A fixColor() 0 6 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\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 Twig_Environment $twigEnvironment The Twig environment.
31
     */
32
    protected function __construct(Twig_Environment $twigEnvironment) {
33
        parent::__construct($twigEnvironment);
34
    }
35
36
    /**
37
     * Fix a color.
38
     *
39
     * @param string $name The color name.
40
     * @param string $prefix The color prefix.
41
     * @return string Returns the prefix color in case of success, default color otherwise.
42
     */
43
    public static function fixColor($name, $prefix = "") {
44
        if (false === array_key_exists($name, DefaultColorProvider::getColors())) {
45
            $name = "red";
46
        }
47
        return $prefix . $name;
48
    }
49
50
}
51