Completed
Push — master ( 0d2e3e...e223e2 )
by Phil
25:52
created

ApplicationStrategy   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 3
dl 0
loc 44
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getCallable() 0 14 2
A getNotFoundDecorator() 0 4 1
A getMethodNotAllowedDecorator() 0 4 1
A getExceptionDecorator() 0 4 1
1
<?php
2
3
namespace League\Route\Strategy;
4
5
use \Exception;
6
use League\Route\Http\Exception\MethodNotAllowedException;
7
use League\Route\Http\Exception\NotFoundException;
8
use League\Route\Middleware\ExecutionChain;
9
use League\Route\Route;
10
use RuntimeException;
11
use Psr\Http\Message\ResponseInterface;
12
use Psr\Http\Message\ServerRequestInterface;
13
14
class ApplicationStrategy implements StrategyInterface
15
{
16
    /**
17
     * {@inheritdoc}
18
     */
19
    public function getCallable(Route $route, array $vars)
20
    {
21 12
        return function (ServerRequestInterface $request, ResponseInterface $response, callable $next) use ($route, $vars) {
22
            $response = call_user_func_array($route->getCallable(), [$request, $response, $vars]);
23
24 12
            if (! $response instanceof ResponseInterface) {
25
                throw new RuntimeException(
26 12
                    'Route callables must return an instance of (Psr\Http\Message\ResponseInterface)'
27
                );
28 9
            }
29 3
30
            return $next($request, $response);
31 3
        };
32
    }
33
34 6
    /**
35 12
     * {@inheritdoc}
36
     */
37 12
    public function getNotFoundDecorator(NotFoundException $exception)
38
    {
39
        throw $exception;
40 12
    }
41
42 12
    /**
43 3
     * {@inheritdoc}
44 12
     */
45
    public function getMethodNotAllowedDecorator(MethodNotAllowedException $exception)
46 12
    {
47
        throw $exception;
48
    }
49
50
    /**
51
     * {@inheritdoc}
52 3
     */
53
    public function getExceptionDecorator(Exception $exception)
54 3
    {
55
        throw $exception;
56
    }
57
}
58