MiscExtension::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Fi\CoreBundle\Twig\Extension;
4
5
use Symfony\Component\DependencyInjection\ContainerInterface;
6
use Twig_Extension;
7
use Twig_SimpleFunction;
8
9
class MiscExtension extends Twig_Extension
0 ignored issues
show
Deprecated Code introduced by
The class Twig_Extension has been deprecated: since Twig 2.7, use "Twig\Extension\AbstractExtension" instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

9
class MiscExtension extends /** @scrutinizer ignore-deprecated */ Twig_Extension
Loading history...
10
{
11
    protected $container;
12
13 35
    public function __construct(ContainerInterface $container)
14
    {
15 35
        $this->container = $container;
16 35
    }
17
18
    public function getFunctions()
19
    {
20
        return array(
21
            new Twig_SimpleFunction('serviceExists', array($this, 'serviceExists')),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFunction has been deprecated: since Twig 2.7, use "Twig\TwigFunction" instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

21
            /** @scrutinizer ignore-deprecated */ new Twig_SimpleFunction('serviceExists', array($this, 'serviceExists')),
Loading history...
22
            new Twig_SimpleFunction('getParameter', array($this, 'getParameter')),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFunction has been deprecated: since Twig 2.7, use "Twig\TwigFunction" instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

22
            /** @scrutinizer ignore-deprecated */ new Twig_SimpleFunction('getParameter', array($this, 'getParameter')),
Loading history...
23
        );
24
    }
25
26 13
    public function getParameter($parameter)
27
    {
28 13
        if ($this->container->hasParameter($parameter)) {
29 13
            return $this->container->getParameter($parameter);
30
        } else {
31
            return '';
32
        }
33
    }
34
35
    public function serviceExists($service)
36
    {
37
        return $this->container->has($service);
38
    }
39
}
40