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

SituationsProxy   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 88.89%

Importance

Changes 0
Metric Value
wmc 6
eloc 12
dl 0
loc 30
ccs 8
cts 9
cp 0.8889
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A call() 0 8 4
A methodExists() 0 3 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