Completed
Push — master ( 2a7c0c...5b0aeb )
by Iman
06:22
created

Chain::reset()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 6
ccs 5
cts 5
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 $predicate;
15
16
    public $responseType = 'nothing';
17
18
    public $data = [];
19
20
    private $beforeResponse = [];
21
22
    public function addRedirect($method, $params)
23
    {
24 93
        $this->data[] = [$method, $params];
25
        $this->responseType = 'redirect';
26 93
    }
27 93
28 93
    public function addResponse($method, $params)
29 93
    {
30 93
        $this->data[] = [$method, $params];
31
        $this->responseType = 'response';
32 4
    }
33
34 4
    public function addException(string $className, string $message)
35 4
    {
36 4
        $this->data[] = ['class' => $className, 'message' => $message];
37
        $this->responseType = 'exception';
38 2
    }
39
40 2
    public function addAbort($code, string $message, array $headers)
41 2
    {
42 2
        $this->data[] = [$code, $message, $headers];
43
        $this->responseType = 'abort';
44 81
    }
45
46 81
    public function addAfterCall($callback, $parameters)
47 81
    {
48 81
        $this->beforeResponse[] = function () use ($callback, $parameters) {
49
            app()->call($callback, $parameters);
50 2
        };
51
    }
52 2
53 2
    public function eventFire($event, array $payload, bool $halt)
54 2
    {
55
        $this->beforeResponse[] = function () use ($event, $payload, $halt) {
56 2
            app('events')->dispatch($event, $payload, $halt);
57
        };
58
    }
59 2
60 1
    public function addRespondFrom($callback, array $parameters)
61 2
    {
62
        $this->data[] = [$callback, $parameters];
63 1
        $this->responseType = 'respondFrom';
64
    }
65
66 1
    public function submitChainConfig()
67 1
    {
68 1
        $callbackListener = app(ReactionFactory::class)->make();
69
        $this->eventManager->commitChain($callbackListener);
70 1
    }
71
72 1
    public function beforeResponse(): \Closure
73 1
    {
74 1
        $calls = $this->beforeResponse;
75
        $this->beforeResponse = [];
76 93
        return function () use ($calls) {
77
            foreach ($calls as $call) {
78 93
                $call();
79 93
            }
80 93
        };
81
    }
82
83
}
84