createReflectionMethodFromCallable()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 3
eloc 4
nc 2
nop 1
1
<?php
2
3
namespace Tonic\Component\Reflection;
4
5
/**
6
 * Static factory for reflection function.
7
 */
8
class ReflectionFunctionFactory
9
{
10
    /**
11
     * @param callable $callable
12
     *
13
     * @return \ReflectionFunctionAbstract
14
     */
15
    public static function createFromCallable(callable $callable)
16
    {
17
        return is_array($callable) && (count($callable) == 2)
18
            ? new \ReflectionMethod($callable[0], $callable[1])
19
            : new \ReflectionFunction($callable);
20
    }
21
22
    /**
23
     * @param callable $callable
24
     *
25
     * @return \ReflectionMethod
26
     */
27
    public static function createReflectionMethodFromCallable(callable $callable)
28
    {
29
        if (is_array($callable) && (count($callable) == 2)) {
30
            return new \ReflectionMethod($callable[0], $callable[1]);
31
        }
32
33
        throw new \InvalidArgumentException('Expects method callable');
34
    }
35
}
36