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

MissingExtension   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
dl 0
loc 39
rs 10
c 1
b 1
f 0
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getFilters() 0 8 1
A getSvg() 0 3 1
A getObjects() 0 12 4
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