Passed
Push — master ( 773906...23c2fd )
by Iman
10:34 queued 07:39
created

SituationsProxy::methodExists()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 2
crap 2
1
<?php
2
3
namespace Imanghafoori\HeyMan\Situations;
4
5
use Imanghafoori\HeyMan\WatchingStrategies\EloquentModels\EloquentSituations;
6
use Imanghafoori\HeyMan\WatchingStrategies\Events\EventSituations;
7
use Imanghafoori\HeyMan\WatchingStrategies\Routes\RouteSituations;
8
use Imanghafoori\HeyMan\WatchingStrategies\Views\ViewSituations;
9
use Imanghafoori\HeyMan\YouShouldHave;
10
11
final class SituationsProxy
12
{
13
    const situations = [
14
        RouteSituations::class,
15
        EloquentSituations::class,
16
        ViewSituations::class,
17
        EventSituations::class,
18
    ];
19
20 105
    public static function call($method, $args)
21
    {
22 105
        $args = is_array($args[0]) ? $args[0] : $args;
23 105
        foreach (self::situations as $className) {
24 105
            if (self::methodExists($method, $className)) {
25 105
                resolve($className)->$method(...$args);
26
27 105
                return resolve(YouShouldHave::class);
28
            }
29
        }
30
    }
31
32
    /**
33
     * @param $method
34
     * @param $className
35
     *
36
     * @return bool
37
     */
38 105
    private static function methodExists($method, $className): bool
39
    {
40 105
        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

40
        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...
41
    }
42
}
43