Passed
Push — master ( ef7ddf...5660db )
by Iman
02:32
created

Situations::call()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 11
ccs 7
cts 7
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
    private static $methodAliases = [];
10
11
    private static $methods = [];
12
13 115
    public static function add($listenerClass, $situation, $methods): void
14
    {
15 115
        foreach ($methods as $method) {
16 115
            self::$methods[$method] = [$listenerClass, $situation];
17
        }
18 115
    }
19
20 111
    public static function call($method, $args)
21
    {
22 111
        $method = self::$methodAliases[$method] ?? $method;
23 111
        $args = is_array($args[0]) ? $args[0] : $args;
24 111
        [$listenerClass, $situation] = self::$methods[$method];
25
26 111
        resolve('heyman.chains')->init(
0 ignored issues
show
Bug introduced by
The method init() does not exist on Illuminate\Foundation\Application. ( Ignorable by Annotation )

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

26
        resolve('heyman.chains')->/** @scrutinizer ignore-call */ init(

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...
27 111
            $listenerClass, ...resolve($situation)->normalize($method, $args)
0 ignored issues
show
Bug introduced by
The method normalize() does not exist on Illuminate\Foundation\Application. ( Ignorable by Annotation )

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

27
            $listenerClass, ...resolve($situation)->/** @scrutinizer ignore-call */ normalize($method, $args)

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...
28
        );
29
30 110
        return resolve(YouShouldHave::class);
31
    }
32
33 2
    public static function aliasMethod($currentName, $newName)
34
    {
35 2
        self::$methodAliases[$newName] = $currentName;
36 2
    }
37
}
38