Passed
Branch master (c65ffc)
by Dāvis
03:08
created

ObjectPositionExtension::getFunctions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 7
rs 9.4285
1
<?php
2
3
namespace Sludio\HelperBundle\Position\Twig;
4
5
use Sludio\HelperBundle\Position\Service\PositionHandler;
6
use Sludio\HelperBundle\Script\Twig\TwigTrait;
7
8
class ObjectPositionExtension extends \Twig_Extension
9
{
10
    use TwigTrait;
11
12
    const NAME = 'position_object';
13
14
    /**
15
     * PositionHandler.
16
     */
17
    private $positionService;
18
19
    public function __construct(PositionHandler $positionService, $container)
20
    {
21
        $this->positionService = $positionService;
22
        $this->shortFunctions = $container->hasParameter('sludio_helper.script.short_functions') && $container->getParameter('sludio_helper.script.short_functions');
0 ignored issues
show
Bug Best Practice introduced by
The property shortFunctions does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
23
    }
24
25
    /**
26
     * Returns the name of the extension.
27
     *
28
     * @return string The extension name
29
     */
30
    public function getName()
31
    {
32
        return self::NAME;
33
    }
34
35
    public function getFunctions()
36
    {
37
        $input = [
38
            self::NAME => 'getter',
39
        ];
40
41
        return $this->makeArray($input, 'function');
42
    }
43
44
    public function getter($entity)
45
    {
46
        $getter = sprintf('get%s', ucfirst($this->positionService->getPositionFieldByEntity($entity)));
47
48
        return $entity->{$getter}();
49
    }
50
}
51