SettingExtension   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 5
c 4
b 0
f 0
lcom 1
cbo 3
dl 0
loc 55
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getFunctions() 0 6 1
A getSettingValue() 0 10 2
A __construct() 0 4 1
A getName() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the ONGR package.
5
 *
6
 * (c) NFQ Technologies UAB <[email protected]>
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 ONGR\SettingsBundle\Twig;
13
14
use ONGR\SettingsBundle\Service\SettingsManager;
15
16
/**
17
 * Class SettingExtension to show settings value on twig.
18
 */
19
class SettingExtension extends \Twig_Extension
20
{
21
    /**
22
     * Extension name
23
     */
24
    const NAME = 'ongr_setting_extension';
25
26
    /**
27
     * @var SettingsManager
28
     */
29
    private $manager;
30
31
    /**
32
     * @param SettingsManager $manager
33
     */
34
    public function __construct($manager)
35
    {
36
        $this->manager = $manager;
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    public function getName()
43
    {
44
        return self::NAME;
45
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50
    public function getFunctions()
51
    {
52
        return [
53
            new \Twig_SimpleFunction('ongr_setting', [$this, 'getSettingValue']),
54
        ];
55
    }
56
57
    /**
58
     * @param string $name
59
     * @param bool   $default
60
     *
61
     * @return mixed
62
     */
63
    public function getSettingValue($name, $default = false)
64
    {
65
        $settingValue = $this->manager->getCachedValue($name);
66
67
        if ($settingValue) {
68
            return $settingValue;
69
        }
70
71
        return $default;
72
    }
73
}
74