Completed
Push — master ( a65afb...9c17f7 )
by Vladimir
11s
created

SelectFilter::flatten()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 6
cts 6
cp 1
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 1
crap 1
1
<?php
2
3
/**
4
 * @copyright 2018 Vladimir Jimenez
5
 * @license   https://github.com/stakx-io/stakx/blob/master/LICENSE.md MIT
6
 */
7
8
namespace allejo\stakx\Templating\Twig\Extension;
9
10
use __;
11
12
class SelectFilter extends AbstractTwigExtension implements TwigFilterInterface
13
{
14 9
    public function __invoke($array, $key, $flatten = true, $distinct = true, $ignore_null = true)
0 ignored issues
show
Coding Style Naming introduced by
The parameter $ignore_null is not named in camelCase.

This check marks parameter names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
15
    {
16 9
        $results = [];
17
18 9
        foreach ($array as $item)
19
        {
20 9
            $results[] = __::get($item, $key);
21
        }
22
23 9
        if ($flatten)
24
        {
25 8
            $results = __::flatten($results);
26
27 8
            if ($distinct)
28
            {
29 6
                $results = array_values(array_unique($results));
30
            }
31
        }
32
33 9
        if ($ignore_null)
34
        {
35 6
            $results = array_values(array_filter($results));
36
        }
37
38 9
        return $results;
39
    }
40
41
    public static function get()
42
    {
43
        return new \Twig_SimpleFilter('select', new self());
44
    }
45
}
46