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

MissingExtension::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\Script\Twig;
4
5
class MissingExtension extends \Twig_Extension
6
{
7
    use TwigTrait;
8
9
    protected $entityManager;
10
11
    public function __construct($entityManager, $shortFunctions)
12
    {
13
        $this->entityManager = $entityManager;
14
        $this->shortFunctions = $shortFunctions;
15
    }
16
17
    public function getFilters()
18
    {
19
        $input = [
20
            'objects' => 'getObjects',
21
            'svg' => 'getSvg',
22
        ];
23
24
        return $this->makeArray($input);
25
    }
26
27
    public function getObjects($class, $variable, $order = null, $one = false)
28
    {
29
        $variable = \is_array($variable) ? $variable : [$variable];
30
        $order = \is_array($order) ? $order : [$order];
31
32
        if ($one) {
33
            $objects = $this->entityManager->getRepository($class)->findOneBy($variable, $order);
34
        } else {
35
            $objects = $this->entityManager->getRepository($class)->findBy($variable, $order);
36
        }
37
38
        return $objects;
39
    }
40
41
    public function getSvg($svg)
42
    {
43
        return file_get_contents(getcwd().$svg);
44
    }
45
}
46