Completed
Push — master ( 1afb1e...a1b796 )
by Korotkov
02:09
created

AbstractHandler   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 0
dl 0
loc 33
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
request() 0 1 ?
A next() 0 12 2
1
<?php
2
3
declare(strict_types = 1);
4
5
/**
6
 * @author    : Korotkov Danila <[email protected]>
7
 * @copyright Copyright (c) 2017, Korotkov Danila
8
 * @license   http://www.gnu.org/licenses/gpl.html GNU GPLv3.0
9
 */
10
11
namespace Behavioral\ChainOfResponsibility;
12
13
/**
14
 * Class AbstractHandler
15
 *
16
 * @package Behavioral\ChainOfResponsibility
17
 */
18
abstract class AbstractHandler
19
{
20
21
    /**
22
     * AbstractHandler constructor.
23
     * @param int   $count
24
     * @param array $chain
25
     */
26
    public function __construct(int $count, array $chain)
27
    {
28
        $this->request();
29
        $this->next($count, $chain);
30
    }
31
32
    abstract public function request();
33
34
    /**
35
     * @param int   $count
36
     * @param array $chain
37
     */
38
    protected function next(int $count, array $chain): void
39
    {
40
        $count--;
41
42
        if ($count) {
43
            array_shift($chain);
44
            $className = $chain[0] ?? $chain;
45
            new $className($count, $chain);
46
        } else {
47
            print "\n";
48
        }
49
    }
50
}
51