Passed
Push — master ( dd9c2f...5ef467 )
by Ryosuke
02:27
created

ReflectionCallable::from()   B

Complexity

Conditions 7
Paths 12

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 7

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 8
cts 8
cp 1
rs 8.8333
c 0
b 0
f 0
cc 7
nc 12
nop 1
crap 7
1
<?php
2
3
namespace Mpyw\EloquentHasByNonDependentSubquery;
4
5
use Closure;
6
use ReflectionFunction;
7
use ReflectionMethod;
8
9
/**
10
 * Class ReflectionCallable
11
 */
12
class ReflectionCallable
13
{
14
    /** @noinspection PhpDocMissingThrowsInspection */
15
16
    /**
17
     * @param  callable                              $callable
18
     * @return \ReflectionFunction|\ReflectionMethod
19
     */
20 6
    public static function from(callable $callable)
21
    {
22 6
        if (\is_string($callable) && \strpos($callable, '::')) {
23 1
            $callable = \explode('::', $callable);
24 6
        } elseif (!$callable instanceof Closure && \is_object($callable)) {
25 1
            $callable = [$callable, '__invoke'];
26
        }
27
28
        /* @noinspection PhpUnhandledExceptionInspection */
29 6
        return $callable instanceof Closure || \is_string($callable)
30 6
            ? new ReflectionFunction($callable)
31 6
            : new ReflectionMethod($callable[0], $callable[1]);
32
    }
33
}
34