Passed
Push — master ( 84b57c...5992dd )
by Alain
02:16
created

Helper::parse_params()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 12
ccs 0
cts 7
cp 0
rs 9.4285
cc 3
eloc 7
nc 3
nop 2
crap 12
1
<?php
2
/**
3
 * Invoker Helper.
4
 *
5
 * @package   BrightNucleus\Invoker
6
 * @author    Alain Schlesser <[email protected]>
7
 * @license   GPL-2.0+
8
 * @link      http://www.brightnucleus.com/
9
 * @copyright 2015-2016 Alain Schlesser, Bright Nucleus
10
 */
11
12
namespace BrightNucleus\Invoker;
13
14
use ReflectionParameter;
15
16
/**
17
 * Helper class that provides a function to parse and reorder parameters.
18
 *
19
 * @since   0.1.5
20
 *
21
 * @package BrightNucleus\Invoker
22
 * @author  Alain Schlesser <[email protected]>
23
 */
24
class Helper
25
{
26
27
    /**
28
     *
29
     *
30
     * @since 0.1.0
31
     *
32
     * @param ReflectionParameter[] $params The reflection parameters to parse.
33
     * @param array                 $args   The arguments to check against.
34
     * @return array The correctly ordered arguments to pass to the reflected callable.
35
     */
36
    public static function parse_params(array $params, $args)
37
    {
38
        $ordered_args = array();
39
40
        foreach ($params as $param) {
41
            $ordered_args[] = array_key_exists($param->name, $args)
42
                ? $args[$param->name]
43
                : $param->getDefaultValue();
44
        }
45
46
        return $ordered_args;
47
    }
48
}
49