Completed
Push — master ( 12114f...959a47 )
by Iman
06:16 queued 01:24
created

WeRespondFrom   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 88.89%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 21
ccs 8
cts 9
cp 0.8889
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A weRespondFrom() 0 5 1
A respondFrom() 0 12 2
1
<?php
2
3
namespace Imanghafoori\HeyMan\Plugins\Reactions;
4
5
use Imanghafoori\HeyMan\Reactions\Then;
6
use Imanghafoori\HeyMan\Core\BaseReaction;
7
use Illuminate\Http\Exceptions\HttpResponseException;
8
9
final class WeRespondFrom extends BaseReaction
10
{
11 1
    public function weRespondFrom($callback, array $parameters = [])
12
    {
13 1
        $this->commit(func_get_args(), [static::class, 'respondFrom']);
14
15 1
        return new Then($this);
16
    }
17
18
    public static function respondFrom($method)
19
    {
20 1
        return function ($meta = null) use ($method) {
21 1
            array_push($method, [$meta]);
22
23 1
            if (is_array($method[0])) {
24
                $response = call_user_func_array(...$method);
0 ignored issues
show
Bug introduced by
The call to call_user_func_array() has too few arguments starting with param_arr. ( Ignorable by Annotation )

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

24
                $response = /** @scrutinizer ignore-call */ call_user_func_array(...$method);

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
25
            } else {
26 1
                $response = app()->call(...$method);
0 ignored issues
show
Bug introduced by
$method is expanded, but the parameter $callback of Illuminate\Container\Container::call() does not expect variable arguments. ( Ignorable by Annotation )

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

26
                $response = app()->call(/** @scrutinizer ignore-type */ ...$method);
Loading history...
27
            }
28
29 1
            throw new HttpResponseException($response);
30 1
        };
31
    }
32
}
33