ReflectionCallable   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 20
ccs 8
cts 8
cp 1
rs 10
wmc 7

1 Method

Rating   Name   Duplication   Size   Complexity  
B from() 0 12 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