ReflectionFunctionFactory   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 6
c 2
b 1
f 0
lcom 0
cbo 0
dl 0
loc 28
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A createFromCallable() 0 6 3
A createReflectionMethodFromCallable() 0 8 3
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