Completed
Push — master ( fa7559...762c49 )
by Iman
03:40
created

ReactionFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
eloc 14
dl 0
loc 28
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A makeReaction() 0 11 1
A make() 0 8 2
1
<?php
2
3
namespace Imanghafoori\HeyMan\Reactions;
4
5
use Imanghafoori\HeyMan\Chain;
6
7
final class ReactionFactory
8
{
9
    /**
10
     * @return \Closure
11
     */
12 94
    public function make(): \Closure
13
    {
14 94
        $reaction = $this->makeReaction();
15 94
        $condition = resolve(Chain::class)->condition;
16
17 94
        return function (...$f) use ($condition, $reaction) {
18 65
            if (!$condition($f)) {
19 54
                $reaction();
20
            }
21 94
        };
22
    }
23
24 94
    private function makeReaction(): \Closure
25
    {
26 94
        $chain = resolve(Chain::class);
27 94
        $responder = resolve(ResponderFactory::class)->make();
28 94
        $beforeResponse = $chain->beforeResponse();
29 94
        $debug = $chain->debugInfo;
30
31 94
        return function () use ($beforeResponse, $responder, $debug) {
32 54
            event('heyman_reaction_is_happening', $debug);
33 54
            $beforeResponse();
34 53
            $responder();
35 94
        };
36
    }
37
}
38