Completed
Push — master ( 1db5f1...1fea5f )
by Beniamin
02:25
created

RecursiveArgs   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 57.14%

Importance

Changes 0
Metric Value
dl 0
loc 34
c 0
b 0
f 0
wmc 4
lcom 0
cbo 0
ccs 8
cts 14
cp 0.5714
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A each() 0 10 3
A map() 0 10 1
1
<?php
2
3
/**
4
 * This file is part of UnderQuery package.
5
 *
6
 * Copyright (c) 2016 Beniamin Jonatan Šimko
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Phuria\UnderQuery\Utils;
13
14
/**
15
 * @author Beniamin Jonatan Šimko <[email protected]>
16
 */
17
class RecursiveArgs
18
{
19
    /**
20
     * @param array    $args
21
     * @param callable $resolver
22
     */
23 2
    public static function each(array $args, callable $resolver)
24
    {
25 2
        foreach ($args as $arg) {
26 2
            if (is_array($arg)) {
27 2
                static::each($arg, $resolver);
28 2
            } else {
29 2
                $resolver($arg);
30
            }
31 2
        }
32 2
    }
33
34
    /**
35
     * @param array    $args
36
     * @param callable $resolver
37
     *
38
     * @return array
39
     */
40
    public static function map(array $args, callable $resolver)
41
    {
42
        $collection = [];
43
44
        static::each($args, function ($arg) use (&$collection, $resolver) {
45
            $collection[] = $resolver($arg);
46
        });
47
48
        return $collection;
49
    }
50
}