Completed
Push — master ( ff5baa...3970bf )
by Korotkov
07:54 queued 04:02
created

Chain::getChain()   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
 * @license   https://mit-license.org/ MIT
8
 */
9
10
namespace Behavioral\ChainOfResponsibility;
11
12
/**
13
 * Class Chain
14
 * @package Behavioral\ChainOfResponsibility
15
 */
16
class Chain
17
{
18
19
    /**
20
     * @var array
21
     */
22
    protected $chain;
23
24
    /**
25
     * @param int $count
26
     */
27
    public function run(int $count): void
28
    {
29
        if (count($this->chain)) {
30
            $firstChain = new $this->chain[0]();
31
            $firstChain($count, $this->chain);
32
        }
33
    }
34
35
    /**
36
     * @param string $className
37
     */
38
    public function addToChain(string $className): void
39
    {
40
        $this->chain[] = $className;
41
    }
42
}
43