Passed
Push — master ( 10b2ca...773906 )
by Iman
07:56
created

SituationsProxy::methodExists()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 6
1
<?php
2
3
namespace Imanghafoori\HeyMan\Situations;
4
5
use Imanghafoori\HeyMan\WatchingStrategies\{EloquentModels\EloquentSituations, Events\EventSituations, Routes\RouteSituations, Views\ViewSituations};
6
use Imanghafoori\HeyMan\YouShouldHave;
7
8
final class SituationsProxy
9
{
10
    const situations = [
11
        RouteSituations::class,
12
        EloquentSituations::class,
13
        ViewSituations::class,
14
        EventSituations::class,
15
    ];
16
17
    public static function call($method, $args)
18
    {
19
        $args = is_array($args[0]) ? $args[0] : $args;
20 105
        foreach (self::situations as $className) {
21
            if (self::methodExists($method, $className)) {
22 105
                resolve($className)->$method(...$args);
23 105
24 105
                return resolve(YouShouldHave::class);
25 105
            }
26
        }
27 105
    }
28
29
    /**
30
     * @param $method
31
     * @param $className
32
     * @return bool
33
     */
34
    private static function methodExists($method, $className): bool
35
    {
36
        return method_exists($className, $method) || resolve($className)->hasMethod($method);
0 ignored issues
show
Bug introduced by
The method hasMethod() does not exist on Illuminate\Foundation\Application. Did you maybe mean hasMethodBinding()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

36
        return method_exists($className, $method) || resolve($className)->/** @scrutinizer ignore-call */ hasMethod($method);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
37
    }
38
}
39