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

ReactionFactory::__construct()   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
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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