Completed
Push — master ( 0a044d...ecf196 )
by Korotkov
14:00 queued 04:13
created

AbstractHandler::setNext()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
nc 1
cc 1
eloc 2
nop 1
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
     * @param int   $count
23
     * @param array $chain
24
     * @return mixed
25
     */
26
    abstract public function request(int $count, array $chain);
27
28
    /**
29
     * @param int   $count
30
     * @param array $chain
31
     */
32
    protected function next(int $count, array $chain): void
33
    {
34
        $count--;
35
36
        if ($count) {
37
            array_shift($chain);
38
            $className = isset($chain[0]) ? $chain[0] : $chain;
39
            $nextClass = new $className;
40
            $nextClass->request($count, $chain);
41
        } else {
42
            print "\n";
43
        }
44
    }
45
}
46