Passed
Push — master ( 8340c5...70ac40 )
by Korotkov
01:28
created

AbstractHandler::next()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 10
rs 10
c 0
b 0
f 0
cc 4
nc 3
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * @author    : Korotkov Danila <[email protected]>
7
 * @license   https://mit-license.org/ MIT
8
 */
9
10
namespace Behavioral\ChainOfResponsibility;
11
12
/**
13
 * Class AbstractHandler
14
 * @package Behavioral\ChainOfResponsibility
15
 */
16
abstract class AbstractHandler
17
{
18
19
    /**
20
     * @param string $event
21
     * @param        $chain
22
     */
23
    abstract public function request(string $event, $chain): void;
24
25
    /**
26
     * @param string $event
27
     * @param        $chain
28
     */
29
    protected function next(string $event, $chain)
30
    {
31
        !is_array($chain) ?: array_shift($chain);
32
33
        if (!count($chain)) {
34
            return;
35
        }
36
37
        $handler = is_array($chain) ? new $chain[0]() : new $chain();
38
        $handler->request($event, $chain);
39
    }
40
}
41