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

AbstractHandler   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
request() 0 1 ?
A next() 0 13 3
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