ReflectionFactory::create()   A
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 5.0488

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 7
cts 8
cp 0.875
rs 9.4222
c 0
b 0
f 0
cc 5
nc 5
nop 1
crap 5.0488
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