Passed
Push — master ( 09ce70...3c2452 )
by Andrea
32:18 queued 16s
created

UtilitaExtension::jsonDecode()   A

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 Cdf\BiCoreBundle\Twig\Extension;
4
5
use Cdf\BiCoreBundle\Utils\Tabella\ParametriTabella;
6
use Twig\Extension\AbstractExtension;
7
use Twig\TwigFilter;
8
use Twig\TwigFunction;
9
10
class UtilitaExtension extends AbstractExtension
11
{
12
    private $container;
13
14 25
    public function __construct($container)
15
    {
16 25
        $this->container = $container;
17 25
    }
18
19
    /**
20
     * {@inheritdoc}
21
     */
22 1
    public function getFunctions()
23
    {
24
        return array(
25 1
            new TwigFunction('json_decode', array($this, 'jsonDecode', 'is_safe' => array('html'))),
26 1
            new TwigFunction('parameter', array($this, 'getParameter', 'is_safe' => array('html'))),
27
        );
28
    }
29
30 1
    public function getFilters()
31
    {
32
        return array(
33 1
            new TwigFilter('getparametrotabella', array($this, 'getParametroTabella')),
34 1
            new TwigFilter('larghezzacolonna', array($this, 'getLarghezzacolonna')),
35
        );
36
    }
37
38 7
    public function jsonDecode($string)
39
    {
40 7
        return json_decode($string);
41
    }
42
43 1
    public function getParameter($parameter)
44
    {
45 1
        return $this->container->getParameter($parameter);
46
    }
47
48 13
    public function getParametroTabella($parametro)
49
    {
50 13
        return ParametriTabella::getParameter($parametro);
51
    }
52
53 7
    public function getLarghezzacolonna($larghezza)
54
    {
55 7
        $class = 'biw-5';
56 7
        if ($larghezza) {
57 7
            $class = 'biw-'.$larghezza;
58
        }
59
60 7
        return $class;
61
    }
62
}
63