Completed
Pull Request — master (#24)
by Alexander
01:59
created

Chain::next()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 1
nop 1
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace alkemann\h2l\util;
4
5
use alkemann\h2l\exceptions;
6
use alkemann\h2l\Request;
7
use alkemann\h2l\Response;
8
9
/**
10
 * Class Chain
11
 *
12
 * @package alkemann\h2l\util
13
 */
14
class Chain
15
{
16
    private $chain;
17
18
    public function __construct(array $chained_callable = [])
19
    {
20
        $this->chain = $chained_callable;
21
    }
22
23
    public function next(Request $request): ?Response
24
    {
25
        if (empty($this->chain)) {
26
            throw new exceptions\EmptyChainError;
27
        }
28
        $next = array_shift($this->chain);
29
        return $next($request, $this);
30
    }
31
}
32