Completed
Push — master ( 91cb0f...c3e82e )
by Iman
17:49 queued 14:46
created

Reactions::commit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
1
<?php
2
3
namespace Imanghafoori\HeyMan\Reactions;
4
5
use Illuminate\Auth\Access\AuthorizationException;
6
use Imanghafoori\HeyMan\Chain;
7
use Imanghafoori\HeyMan\Reactions\Redirect\Redirector;
8
9
final class Reactions
10
{
11
    use BeforeReaction;
12
13 2
    public function response(): Responder
14
    {
15 2
        return new Responder($this);
16
    }
17
18 7
    public function redirect(): Redirector
19
    {
20 7
        return new Redirector($this);
21
    }
22
23 4
    public function weThrowNew(string $exception, string $message = '')
24
    {
25 4
        $this->commit(func_get_args(), 'exception');
26
27 4
        return new Then($this);
28
    }
29
30 2
    public function abort($code, string $message = '', array $headers = [])
31
    {
32 2
        $this->commit(func_get_args(), __FUNCTION__);
33
34 2
        return new Then($this);
35
    }
36
37 1
    public function weRespondFrom($callback, array $parameters = [])
38
    {
39 1
        $this->commit(func_get_args(), 'respondFrom');
40
41 1
        return new Then($this);
42
    }
43
44 81
    public function weDenyAccess(string $message = '')
45
    {
46 81
        $this->commit([AuthorizationException::class, $message], 'exception');
47
48 81
        return new Then($this);
49
    }
50
51 93
    public function __destruct()
52
    {
53 93
        resolve(Chain::class)->submitChainConfig();
54 93
    }
55
56 84
    private function commit($args, $methodName)
57
    {
58 84
        resolve(Chain::class)->commitCalledMethod($args, $methodName);
59 84
    }
60
}
61