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

ApplicationStrategy::getCallable()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 6
cts 6
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 7
nc 1
nop 2
crap 2
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