HandlerFactory::create()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of PHPinnacle/Ensign.
4
 *
5
 * (c) PHPinnacle Team <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
declare(strict_types = 1);
12
13
namespace PHPinnacle\Ensign;
14
15
final class HandlerFactory
16
{
17
    /**
18
     * @var HandlerWrapper[]
19
     */
20
    private $wrappers = [];
21
22
    /**
23
     * @param HandlerWrapper $wrapper
24
     *
25
     * @return self
26
     */
27 1
    public function with(HandlerWrapper $wrapper): self
28
    {
29 1
        $this->wrappers[] = $wrapper;
30
31 1
        return $this;
32
    }
33
34
    /**
35
     * @param callable $handler
36
     *
37
     * @return callable
38
     */
39 3
    public function create(callable $handler): callable
40
    {
41 3
        foreach ($this->wrappers as $wrapper) {
42 1
            $handler = $wrapper->wrap($handler);
43
        }
44
45 3
        return $handler;
46
    }
47
}
48