Completed
Push — master ( 44cd2c...638a5b )
by Daniel
05:15
created

StaticArr::__callStatic()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 2
Metric Value
c 3
b 0
f 2
dl 0
loc 16
rs 9.4286
cc 3
eloc 9
nc 3
nop 2
1
<?php
2
namespace Narrowspark\Arr;
3
4
use BadMethodCallException;
5
6
/**
7
 * Class StaticArr
8
 */
9
class StaticArr
10
{
11
    /**
12
     * Creates an instance of Arr and invokes the given method with the
13
     * rest of the passed arguments.
14
     * The result is not cast, so the return value may be of type Arr, array,
15
     * integer, boolean, etc.
16
     *
17
     * @param string  $name
18
     * @param mixed[] $arguments
19
     *
20
     * @throws \BadMethodCallException
21
     *
22
     * @return mixed
23
     */
24
    public static function __callStatic($name, $arguments)
25
    {
26
        if (!isset(static::$methodArgs[$name])) {
27
            throw new BadMethodCallException($name . ' is not a valid method');
28
        }
29
30
        $numArgs = count($arguments);
31
32
        if ($numArgs === static::$methodArgs[$name]) {
33
            $args = array_slice($arguments, 1, -1);
34
        } else {
35
            $args = array_slice($arguments, 1);
36
        }
37
38
        return call_user_func_array([new Arr(), $name], $args);
39
    }
40
}
41