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

ExtendHashFilter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 0
cbo 1
dl 0
loc 17
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 9 2
A get() 0 4 1
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