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

ObjectToTabellaExtension   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 40
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A field2Object() 0 5 1
A object2View() 0 5 1
A joinFieldId() 0 8 2
A getFunctions() 0 6 1
1
<?php
2
3
namespace Cdf\BiCoreBundle\Twig\Extension;
4
5
use Cdf\BiCoreBundle\Utils\Entity\DoctrineFieldReader;
6
use Twig\Extension\AbstractExtension;
7
use Twig\TwigFunction;
8
9
class ObjectToTabellaExtension extends AbstractExtension
10
{
11
    private $tableprefix;
12
13 25
    public function __construct($tableprefix)
14
    {
15 25
        $this->tableprefix = $tableprefix;
16 25
    }
17
18 1
    public function getFunctions()
19
    {
20
        return array(
21 1
            new TwigFunction('object2view', array($this, 'object2View', 'is_safe' => array('html'))),
22 1
            new TwigFunction('field2object', array($this, 'field2Object', 'is_safe' => array('html'))),
23 1
            new TwigFunction('joinfieldid', array($this, 'joinFieldId', 'is_safe' => array('html'))),
24
        );
25
    }
26
27 7
    public function object2View($object, $type = null, $decodifiche = null)
28
    {
29 7
        $dfr = new DoctrineFieldReader($this->tableprefix);
30
31 7
        return $dfr->object2View($object, $type, $decodifiche);
32
    }
33
34 7
    public function field2Object($fieldname, $object, $decodifiche = null)
35
    {
36 7
        $dfr = new DoctrineFieldReader($this->tableprefix);
37
38 7
        return $dfr->getField2Object($fieldname, $object, $decodifiche);
39
    }
40
41 3
    public function joinFieldId($object)
42
    {
43 3
        $valore = null;
44 3
        if ($object) {
45 2
            $valore = $object->getId();
46
        }
47
48 3
        return $valore;
49
    }
50
}
51