Completed
Push — master ( 43cd61...c32de9 )
by Iman
05:22
created

SituationsProxy   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 88.89%

Importance

Changes 0
Metric Value
wmc 6
eloc 8
dl 0
loc 25
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\Core;
4
5
use Imanghafoori\HeyMan\YouShouldHave;
6
7
final class SituationsProxy
8
{
9
    public static $situations = [];
10
11 106
    public static function call($method, $args)
12
    {
13 106
        $args = is_array($args[0]) ? $args[0] : $args;
14 106
        foreach (self::$situations as $className) {
15 106
            if (self::methodExists($method, $className)) {
16 106
                resolve($className)->$method(...$args);
17
18 105
                return resolve(YouShouldHave::class);
19
            }
20
        }
21
    }
22
23
    /**
24
     * @param string $method
25
     * @param string $className
26
     *
27
     * @return bool
28
     */
29 106
    private static function methodExists(string $method, string $className): bool
30
    {
31 106
        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

31
        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...
32
    }
33
}
34