Completed
Push — master ( c6b6d5...70eeeb )
by Iman
06:33
created

Reactions   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 64
ccs 25
cts 25
cp 1
rs 10
c 0
b 0
f 0
wmc 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A redirect() 0 3 1
A response() 0 3 1
A __construct() 0 3 1
A weThrowNew() 0 3 1
A afterCalling() 0 5 1
A abort() 0 3 1
A __destruct() 0 3 1
A weDenyAccess() 0 3 1
A afterFiringEvent() 0 5 1
A weRespondFrom() 0 3 1
1
<?php
2
3
namespace Imanghafoori\HeyMan;
4
5
use Illuminate\Auth\Access\AuthorizationException;
6
7
class Reactions
8
{
9
    /**
10
     * @var \Imanghafoori\HeyMan\Chain
11
     */
12
    private $chain;
13
14
    /**
15
     * Actions constructor.
16
     *
17
     * @param \Imanghafoori\HeyMan\Chain $chain
18
     */
19 76
    public function __construct(Chain $chain)
20
    {
21 76
        $this->chain = $chain;
22 76
    }
23
24 2
    public function response(): Responder
25
    {
26 2
        return new Responder($this->chain, $this);
27
    }
28
29 5
    public function redirect(): Redirector
30
    {
31 5
        return new Redirector($this->chain, $this);
32
    }
33
34 2
    public function afterCalling($callback, array $parameters = []): self
35
    {
36 2
        $this->chain->addAfterCall($callback, $parameters);
37
38 2
        return $this;
39
    }
40
41 1
    public function weThrowNew(string $exception, string $message = '')
42
    {
43 1
        $this->chain->addException($exception, $message);
44 1
    }
45
46 2
    public function abort($code, string $message = '', array $headers = [])
47
    {
48 2
        $this->chain->addAbort($code, $message, $headers);
49 2
    }
50
51 67
    public function weRespondFrom($callback, array $parameters = [])
52
    {
53 67
        $this->chain->addRespondFrom($callback, $parameters);
54 67
    }
55
56 1
    public function weDenyAccess(string $message = '')
57
    {
58 1
        $this->chain->addException(AuthorizationException::class, $message);
59
    }
60 1
61
    public function afterFiringEvent($event, $payload = [], $halt = false): self
62
    {
63 76
        $this->chain->eventFire($event, $payload, $halt);
64
65 76
        return $this;
66 76
    }
67
68
    public function __destruct()
69
    {
70
        app(Chain::class)->submitChainConfig();
71
    }
72
}
73