Passed
Push — master ( 6b2a37...7cbd7b )
by Jelmer
05:33
created

Delegate   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 21
ccs 8
cts 8
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A process() 0 10 2
1
<?php declare(strict_types = 1);
2
3
namespace jschreuder\Middle;
4
5
use Interop\Http\Middleware\DelegateInterface;
6
use Interop\Http\Middleware\MiddlewareInterface;
7
use Psr\Http\Message\RequestInterface;
8
use Psr\Http\Message\ResponseInterface;
9
10
final class Delegate implements DelegateInterface
11
{
12
    /** @var  \SplStack */
13
    private $stack;
14
15 5
    public function __construct(\SplStack $stack)
16
    {
17 5
        $this->stack = $stack;
18 5
    }
19
20 3
    public function process(RequestInterface $request) : ResponseInterface
21
    {
22 3
        if ($this->stack->count() === 0) {
23 1
            throw new \RuntimeException('No more middleware\'s to call on.');
24
        }
25
26
        /** @var  MiddlewareInterface $next */
27 3
        $next = $this->stack->pop();
28 3
        return $next->process($request, $this);
29
    }
30
}
31