ObjectToTabellaExtension   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 59
ccs 19
cts 19
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 joinFieldId() 0 8 2
A field2Object() 0 5 1
A object2View() 0 5 1
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 string $tableprefix;
12
13 25
    public function __construct(string $tableprefix)
14
    {
15 25
        $this->tableprefix = $tableprefix;
16
    }
17
18 1
    public function getFunctions(): array
19
    {
20 1
        return array(
21 1
            new TwigFunction('object2view', [$this, 'object2View']),
22 1
            new TwigFunction('field2object', [$this, 'field2Object']),
23 1
            new TwigFunction('joinfieldid', [$this, 'joinFieldId']),
24 1
        );
25
    }
26
27
    /**
28
     *
29
     * @param mixed $object
30
     * @param string $type
31
     * @param array<mixed> $decodifiche
32
     * @return mixed|null
33
     */
34 7
    public function object2View($object, ?string $type = null, $decodifiche = null)
35
    {
36 7
        $dfr = new DoctrineFieldReader($this->tableprefix);
37
38 7
        return $dfr->object2View($object, $type, $decodifiche);
39
    }
40
41
    /**
42
     *
43
     * @param string $fieldname
44
     * @param mixed $object
45
     * @param array<mixed> $decodifiche
46
     * @return mixed|null
47
     */
48 7
    public function field2Object($fieldname, $object, $decodifiche = null)
49
    {
50 7
        $dfr = new DoctrineFieldReader($this->tableprefix);
51
52 7
        return $dfr->getField2Object($fieldname, $object, $decodifiche);
53
    }
54
55
    /**
56
     *
57
     * @param mixed $object
58
     * @return int|null
59
     */
60 3
    public function joinFieldId($object)
61
    {
62 3
        $valore = null;
63 3
        if ($object) {
64 2
            $valore = $object->getId();
65
        }
66
67 3
        return $valore;
68
    }
69
}
70