Completed
Push — feature/sass-standard ( f943ac...ee57cf )
by Vladimir
04:18
created

ExtendHashFilter::get()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace BZIon\Twig;
4
5
/**
6
 * A Twig filter that when given a base associative array (a.k.a. hash) will recursively merge another array recursively
7
 * on top of the base. This is different from using the `default` filter which only sets a value when the variable is
8
 * null.
9
 */
10
class ExtendHashFilter
11
{
12
    public function __invoke($array, $base)
13
    {
14
        if (!is_array($array))
15
        {
16
            $array = [$array];
17
        }
18
19
        return array_merge_recursive($base, $array);
20
    }
21
22
    public static function get()
23
    {
24
        return new \Twig_SimpleFilter('extend_hash', new self());
25
    }
26
}
27