Passed
Push — master ( 6b98e6...e3cd39 )
by Jelmer
06:12
created

Delegate::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 1
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php declare(strict_types = 1);
2
3
namespace jschreuder\Middle;
4
5
use Interop\Http\Middleware\DelegateInterface;
6
use Psr\Http\Message\RequestInterface;
7
use Psr\Http\Message\ResponseInterface;
8
9
final class Delegate implements DelegateInterface
10
{
11
    /** @var  \SplStack */
12
    private $stack;
13
14 2
    public function __construct(\SplStack $stack)
15
    {
16 2
        $this->stack = $stack;
17 2
    }
18
19
    public function next(RequestInterface $request) : ResponseInterface
20
    {
21
        if ($this->stack->count() === 0) {
22
            throw new \RuntimeException('No more middleware\'s to call on.');
23
        }
24
25
        /** @var  HttpMiddlewareInterface $next */
26
        $next = $this->stack->pop();
27
        return $next->process($request, $this);
28
    }
29
}
30