Passed
Push — master ( b38da1...a59646 )
by Dāvis
04:33
created

ObjectPositionExtension   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 31
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getter() 0 5 1
A getFunctions() 0 7 1
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, $shortFunctions)
20
    {
21
        $this->positionService = $positionService;
22
        $this->shortFunctions = $shortFunctions;
23
    }
24
25
    public function getFunctions()
26
    {
27
        $input = [
28
            self::NAME => 'getter',
29
        ];
30
31
        return $this->makeArray($input, 'function');
32
    }
33
34
    public function getter($entity)
35
    {
36
        $getter = sprintf('get%s', ucfirst($this->positionService->getPositionFieldByEntity($entity)));
37
38
        return $entity->{$getter}();
39
    }
40
}
41