reflectionFunction()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 7
nc 4
nop 1
dl 0
loc 15
rs 9.2
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Scalp\Reflection {
6
    function reflectionFunction(callable $f): \ReflectionFunctionAbstract
7
    {
8
        if (is_object($f)) {
9
            return (new \ReflectionObject($f))->getMethod('__invoke');
10
        }
11
12
        if (isClassStaticMethodCall($f)) {
13
            return (new \ReflectionClass($f[0]))->getMethod($f[1]);
14
        }
15
16
        if (isObjectMethodCall($f)) {
17
            return (new \ReflectionObject($f[0]))->getMethod($f[1]);
18
        }
19
20
        return new \ReflectionFunction($f);
21
    }
22
23
    function isClassStaticMethodCall(callable $f): bool
24
    {
25
        return isMethodCall($f) && is_string($f[0]);
26
    }
27
28
    function isObjectMethodCall(callable $f): bool
29
    {
30
        return isMethodCall($f) && is_object($f[0]);
31
    }
32
33
    function isMethodCall(callable $f): bool
34
    {
35
        return is_array($f) && is_string($f[1]);
36
    }
37
}
38