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

RecursiveArgs::each()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 10
c 0
b 0
f 0
ccs 8
cts 8
cp 1
rs 9.4285
cc 3
eloc 6
nc 3
nop 2
crap 3
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
}