WeRespondFrom::respondFrom()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 2
Bugs 1 Features 0
Metric Value
cc 2
eloc 6
c 2
b 1
f 0
nc 1
nop 1
dl 0
loc 10
ccs 5
cts 5
cp 1
crap 2
rs 10
1
<?php
2
3
namespace Imanghafoori\HeyMan\Plugins\Reactions;
4
5
use Illuminate\Http\Exceptions\HttpResponseException;
6
use Imanghafoori\HeyMan\Core\BaseReaction;
7
use Imanghafoori\HeyMan\Reactions\Then;
8
9
final class WeRespondFrom extends BaseReaction
10
{
11 3
    public function weRespondFrom($callback, array $parameters = [])
12
    {
13 3
        $this->commit(func_get_args(), [static::class, 'respondFrom']);
14
15 3
        return new Then($this);
16
    }
17
18
    public static function respondFrom($method)
19
    {
20 3
        return function () use ($method) {
21 3
            if (is_array($method[0])) {
22 2
                $response = call_user_func_array($method[0], $method[1] ?? []);
23
            } else {
24 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

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