Completed
Push — master ( d9bece...2ea354 )
by Andrea
10:06
created

MiscExtension   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 76.92%

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
lcom 0
cbo 3
dl 0
loc 31
ccs 10
cts 13
cp 0.7692
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getParameter() 0 8 2
A serviceExists() 0 4 1
A getFunctions() 0 7 1
1
<?php
2
3
namespace Fi\CoreBundle\Twig\Extension;
4
5
use Symfony\Component\DependencyInjection\ContainerInterface;
6
7
class MiscExtension extends \Twig_Extension
8
{
9
    protected $container;
10
11 17
    public function __construct(ContainerInterface $container)
12
    {
13 17
        $this->container = $container;
14 17
    }
15
16 10
    public function getFunctions()
17
    {
18
        return array(
19 10
            new \Twig_SimpleFunction('serviceExists', array($this, 'serviceExists')),
20 10
            new \Twig_SimpleFunction('getParameter', array($this, 'getParameter')),
21 10
        );
22
    }
23
24 10
    public function getParameter($parameter)
25
    {
26 10
        if ($this->container->hasParameter($parameter)) {
27 10
            return $this->container->getParameter($parameter);
28
        } else {
29
            return '';
30
        }
31
    }
32
33
    public function serviceExists($service)
34
    {
35
        return $this->container->has($service);
36
    }
37
}
38