Passed
Push — master ( e66282...39a592 )
by Dāvis
02:46
created

TwigTrait::makeArray()   B

Complexity

Conditions 4
Paths 6

Size

Total Lines 22
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 13
nc 6
nop 3
dl 0
loc 22
rs 8.9197
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
    public function makeArray(array $input, $type = 'filter', $onlyShort = false)
10
    {
11
        if($onlyShort){
12
            $this->shortFunctions = true;
13
        }
14
        $output = [];
15
        $class = '\\Twig_Simple'.ucfirst($type);
16
17
        foreach ($input as $call => $function) {
18
            $output[] = new $class('sludio_'.$call, [
19
                $this,
20
                $function,
21
            ]);
22
            if ($this->shortFunctions) {
23
                $output[] = new $class($call, [
24
                    $this,
25
                    $function,
26
                ]);
27
            }
28
        }
29
30
        return $output;
31
    }
32
}