GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Branch 1.0 (53c4b5)
by Quim
03:22
created

RequestResponseDispatcher::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 5
cts 5
cp 1
rs 9.4286
cc 2
eloc 3
nc 2
nop 1
crap 2
1
<?php
2
namespace QuimCalpe\Router\Dispatchers;
3
4
use QuimCalpe\Router\Route\ParsedRoute;
5
use Symfony\Component\HttpFoundation\Request;
6
use Symfony\Component\HttpFoundation\Response;
7
use RuntimeException;
8
9
class RequestResponseDispatcher implements DispatcherInterface
10
{
11
    /**
12
     * @var \Symfony\Component\HttpFoundation\Request
13
     */
14
    private $request = null;
15
16
    /**
17
     * @param Request|null $request
18
     */
19 5
    public function __construct(Request $request = null)
20
    {
21 5
        if (isset($request)) {
22 1
            $this->request = $request;
23 1
        }
24 5
    }
25
26
    /**
27
     * @param ParsedRoute $route
28
     * @return Response
29
     *
30
     * @throws RuntimeException
31
     */
32 5
    public function handle(ParsedRoute $route)
33
    {
34 5
        $segments = explode("::", $route->controller());
35 5
        $controller = $segments[0];
36 5
        $action = count($segments) > 1 ? $segments[1] : "index";
37 5
        if (method_exists($controller, $action)) {
38 4
            if (!isset($this->request)) {
39 3
                $this->request = Request::createFromGlobals();
40 3
            }
41 4
            $params = [$this->request, new Response()];
42 4
            if (count($route->params())) {
43 1
                $params[] = $route->params();
44 1
            }
45 4
            return call_user_func_array([new $controller(), $action], $params);
46
        } else {
47 1
            throw new RuntimeException("No method {$action} in controller {$segments[0]}");
48
        }
49
    }
50
}
51