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.
Passed
Branch master (18840e)
by Jason
05:36
created

Allow::__invoke()   B

Complexity

Conditions 4
Paths 6

Size

Total Lines 26
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 4.0312

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 26
ccs 14
cts 16
cp 0.875
rs 8.5806
cc 4
eloc 16
nc 6
nop 3
crap 4.0312
1
<?php
2
3
namespace JDesrosiers\Silex\Provider;
4
5
use Silex\Application;
6
use Symfony\Component\HttpFoundation\Request;
7
use Symfony\Component\HttpFoundation\Response;
8
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
9
use Symfony\Component\Routing\Exception\MethodNotAllowedException;
10
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
11
12
class Allow
13
{
14 23
    public function __invoke(Request $request, Response $response, Application $app)
15
    {
16 23
        $requestMethod = $app["request_context"]->getMethod();
17 23
        $app["request_context"]->setMethod("NOTAMETHOD");
18
19
        try {
20 23
            $app["request_matcher"]->match($request->getPathInfo());
21
            $allow = []; // Should never get here
22 23
        } catch (MethodNotAllowedException $e) {
23 23
            $allow = array_filter($e->getAllowedMethods(), function ($method) {
24 23
                return $method != "OPTIONS";
25 23
            });
26 23
        } catch (ResourceNotFoundException $e) {
27
            $allow = []; // Should never get here
28
        }
29
30 23
        $app["request_context"]->setMethod($requestMethod);
31
32 23
        if (count($allow) === 0) {
33 1
            throw new NotFoundHttpException();
34
        }
35
36 22
        $response->headers->set("Allow", implode(",", $allow));
37
38 22
        return $response;
39
    }
40
}
41