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

TwigTrait::makeArray()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 13
nc 4
nop 2
dl 0
loc 20
rs 9.2
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 = isset($function[2]) ? $function[2] : [];
18
                unset($function[2]);
19
                $output[] = new $class($call, $function, $options);
20
            } else {
21
                $output[] = new $class($call, [
22
                    $this,
23
                    $function,
24
                ]);
25
            }
26
        }
27
28
        return $output;
29
    }
30
31
    private function makeInput(array $input, &$output)
32
    {
33
        $output = [];
34
        foreach ($input as $call => $function) {
35
            if ($this->shortFunctions) {
36
                $output[$call] = $function;
37
            }
38
            $output['sludio_'.$call] = $function;
39
        }
40
    }
41
}
42