Passed
Push — master ( 86c965...1f415b )
by Dāvis
02:56
created

TwigTrait::makeInput()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

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