Passed
Push — master ( e3cd39...44beaa )
by Jelmer
03:07
created

Delegate::next()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
crap 2
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 5
    public function __construct(\SplStack $stack)
15
    {
16 5
        $this->stack = $stack;
17 5
    }
18
19 3
    public function next(RequestInterface $request) : ResponseInterface
20
    {
21 3
        if ($this->stack->count() === 0) {
22 1
            throw new \RuntimeException('No more middleware\'s to call on.');
23
        }
24
25
        /** @var  HttpMiddlewareInterface $next */
26 3
        $next = $this->stack->pop();
27 3
        return $next->process($request, $this);
28
    }
29
}
30