ReflectionFactory   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 87.5%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 0
dl 0
loc 28
ccs 7
cts 8
cp 0.875
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A create() 0 16 5
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the rybakit/arguments-resolver package.
7
 *
8
 * (c) Eugene Leonovich <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace ArgumentsResolver;
15
16
abstract class ReflectionFactory
17
{
18
    /**
19
     * Creates a reflection for a given function.
20
     *
21
     * @param callable|string $function A callable or a string representing a class method (non-static, delimited by ::)
22
     *
23
     * @throws \ReflectionException
24
     *
25
     * @return \ReflectionFunction|\ReflectionMethod
26
     */
27 9
    public static function create($function) : \ReflectionFunctionAbstract
28
    {
29 9
        if (\is_string($function)) {
30 2
            return \strpos($function, '::') ? new \ReflectionMethod($function) : new \ReflectionFunction($function);
31
        }
32
33 7
        if (\is_array($function)) {
34 5
            return (new \ReflectionClass(\ReflectionMethod::class))->newInstanceArgs($function);
35
        }
36
37 2
        if (\method_exists($function, '__invoke')) {
38 2
            return new \ReflectionMethod($function, '__invoke');
39
        }
40
41
        return new \ReflectionFunction($function);
42
    }
43
}
44