Completed
Pull Request — master (#13)
by Paweł
03:59 queued 01:37
created

isClassStaticMethodCall()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 1
nc 2
nop 1
dl 0
loc 3
rs 10
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