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

ObjectToTabellaExtension::getFunctions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 6
ccs 4
cts 4
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\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