Passed
Push — master ( db039c...4d8c20 )
by Dāvis
04:33
created

TwigTrait::makeArray()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 23
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 15
nc 4
nop 2
dl 0
loc 23
rs 8.7972
c 0
b 0
f 0
1
<?php
2
3
namespace Sludio\HelperBundle\Script\Twig;
4
5
trait TwigTrait
6
{
7
    private $shortFunctions;
8
9
    public function makeArray(array $input, $type = 'filter')
10
    {
11
        $output = [];
12
        $class = '\\Twig_Simple'.ucfirst($type);
13
        $this->makeInput($input, $input);
14
15
        foreach ($input as $call => $function) {
16
            if (\is_array($function)) {
17
                $options = [];
18
                if (isset($function[2])) {
19
                    $options[] = $function[2];
20
                    unset($function[2]);
21
                }
22
                $output[] = new $class($call, $function, $options);
23
            } else {
24
                $output[] = new $class($call, [
25
                    $this,
26
                    $function,
27
                ]);
28
            }
29
        }
30
31
        return $output;
32
    }
33
34
    private function makeInput(array $input, &$output)
35
    {
36
        $output = [];
37
        foreach ($input as $call => $function) {
38
            if ($this->shortFunctions) {
39
                $output[$call] = $function;
40
            }
41
            $output['sludio_'.$call] = $function;
42
        }
43
    }
44
}
45