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

AbstractHandler   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 6
dl 0
loc 23
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A next() 0 10 4
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