Passed
Push — master ( 70b3d4...d3498e )
by Iman
02:17
created

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

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