Completed
Push — master ( 6e909e...c441c1 )
by Phil
03:17
created

ExecutionChain   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A execute() 0 5 1
A buildExecutionChain() 0 16 2
1
<?php
2
3
namespace League\Route\Middleware;
4
5
use Psr\Http\Message\ResponseInterface;
6
use Psr\Http\Message\ServerRequestInterface;
7
8
class ExecutionChain implements StackAwareInterface
9
{
10
    use StackAwareTrait;
11
12
    /**
13
     * Build and execute the chain.
14
     *
15
     * @param \Psr\Http\Message\ServerRequestInterface $request
16
     * @param \Psr\Http\Message\ResponseInterface      $response
17
     *
18
     * @return \Psr\Http\Message\ResponseInterface
19
     */
20 33
    public function execute(ServerRequestInterface $request, ResponseInterface $response)
21
    {
22 33
        $chain = $this->buildExecutionChain();
23 33
        return $chain($request, $response);
24
    }
25
26
    /**
27
     * Build an execution chain.
28
     *
29
     * @return callable
30
     */
31 33
    protected function buildExecutionChain()
32
    {
33 33
        $stack = $this->getMiddlewareStack();
34
35
        $next = function (ServerRequestInterface $request, ResponseInterface $response) {
36 12
            return $response;
37 33
        };
38
39 33
        foreach ($stack as $middleware) {
40 33
            $next = function (ServerRequestInterface $request, ResponseInterface $response) use ($middleware, $next) {
41 33
                return $middleware($request, $response, $next);
42 33
            };
43 33
        }
44
45 33
        return $next;
46
    }
47
}
48