Completed
Push — master ( 6feb1d...a52e49 )
by Iman
04:44
created

Chain::commitArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Imanghafoori\HeyMan;
4
5
use Imanghafoori\HeyMan\Reactions\ReactionFactory;
6
7
class Chain
8
{
9
    /**
10
     * @var \Imanghafoori\HeyMan\ListenerApplier
0 ignored issues
show
Bug introduced by
The type Imanghafoori\HeyMan\ListenerApplier was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
     */
12
    public $eventManager;
13
14
    public $debugInfo;
15
16
    public $condition;
17
18
    public $responseType = 'nothing';
19
20
    public $data = [];
21
22
    private $beforeResponse = [];
23
24 2
    public function addAfterCall($callback, $parameters)
25
    {
26
        $this->beforeResponse[] = function () use ($callback, $parameters) {
27 2
            app()->call($callback, $parameters);
28 1
        };
29 2
    }
30
31 1
    public function eventFire($event, array $payload, bool $halt)
32
    {
33
        $this->beforeResponse[] = function () use ($event, $payload, $halt) {
34 1
            app('events')->dispatch($event, $payload, $halt);
35 1
        };
36 1
    }
37
38 93
    public function submitChainConfig()
39
    {
40 93
        $callbackListener = app(ReactionFactory::class)->make();
41 93
        $this->eventManager->commitChain($callbackListener);
42 93
    }
43
44 93
    public function beforeResponse(): \Closure
45
    {
46 93
        $calls = $this->beforeResponse;
47 93
        $this->beforeResponse = [];
48
49
        return function () use ($calls) {
50 52
            foreach ($calls as $call) {
51 3
                $call();
52
            }
53 93
        };
54
    }
55
56 83
    public function commit($args, $methodName)
57
    {
58 83
        $this->data = $args;
59 83
        $this->responseType = $methodName;
60 83
    }
61
62 5
    public function commitArray($args, $methodName)
63
    {
64 5
        $this->data[] = $args;
65 5
        $this->responseType = $methodName;
66 5
    }
67
}
68