ObjectToTabellaExtension::joinFieldId()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 8
ccs 5
cts 5
cp 1
crap 2
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 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