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

Chain   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

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