Passed
Branch master (a0cc06)
by Dāvis
17:06
created

ObjectPositionExtension::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Sludio\HelperBundle\Position\Twig;
4
5
use Sludio\HelperBundle\Position\Service\PositionHandler;
6
use Twig_Extension;
7
use Twig_SimpleFunction;
8
9
class ObjectPositionExtension extends Twig_Extension
10
{
11
    const NAME = 'sludio_position_object';
12
13
    /**
14
     * PositionHandler.
15
     */
16
    private $positionService;
17
18
    public function __construct(PositionHandler $positionService)
19
    {
20
        $this->positionService = $positionService;
21
    }
22
23
    /**
24
     * Returns the name of the extension.
25
     *
26
     * @return string The extension name
27
     */
28
    public function getName()
29
    {
30
        return self::NAME;
31
    }
32
33
    public function getFunctions()
34
    {
35
        return [
36
            new Twig_SimpleFunction(self::NAME, function ($entity) {
37
                $getter = sprintf('get%s', ucfirst($this->positionService->getPositionFieldByEntity($entity)));
38
39
                return $entity->{$getter}();
40
            }),
41
        ];
42
    }
43
}
44