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

AbstractHandler::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 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