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

UtilitaExtension   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 51
ccs 20
cts 20
cp 1
rs 10
c 0
b 0
f 0
wmc 8

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A jsonDecode() 0 3 1
A getLarghezzacolonna() 0 8 2
A getParameter() 0 3 1
A getParametroTabella() 0 3 1
A getFilters() 0 5 1
A getFunctions() 0 5 1
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