ApplicationStrategy   A
last analyzed

Coupling/Cohesion

Components 0
Dependencies 3

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 3
dl 0
loc 44
ccs 13
cts 13
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\Route;
9
use RuntimeException;
10
use Psr\Http\Message\ResponseInterface;
11
use Psr\Http\Message\ServerRequestInterface;
12
13
class ApplicationStrategy implements StrategyInterface
14
{
15
    /**
16
     * [email protected]}
17
     */
18
    public function getCallable(Route $route, array $vars)
19
    {
20 9
        return function (ServerRequestInterface $request, ResponseInterface $response, callable $next) use ($route, $vars) {
21 9
            $response = call_user_func_array($route->getCallable(), [$request, $response, $vars]);
22
23 6
            if (! $response instanceof ResponseInterface) {
24 3
                throw new RuntimeException(
25
                    'Route callables must return an instance of (Psr\Http\Message\ResponseInterface)'
26 3
                );
27
            }
28
29 3
            return $next($request, $response);
30 9
        };
31
    }
32
33
    /**
34
     * [email protected]}
35
     */
36 3
    public function getNotFoundDecorator(NotFoundException $exception)
37
    {
38 3
        throw $exception;
39
    }
40
41
    /**
42
     * [email protected]}
43
     */
44 3
    public function getMethodNotAllowedDecorator(MethodNotAllowedException $exception)
45
    {
46 3
        throw $exception;
47
    }
48
49
    /**
50
     * [email protected]}
51
     */
52 3
    public function getExceptionDecorator(Exception $exception)
53
    {
54 3
        throw $exception;
55
    }
56
}
57