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.

GetResourceController::__invoke()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.7333
c 0
b 0
f 0
cc 3
nc 3
nop 2
ccs 9
cts 9
cp 1
crap 3
1
<?php
2
3
namespace JDesrosiers\Resourceful\Controller;
4
5
use Doctrine\Common\Cache\Cache;
6
use JDesrosiers\Resourceful\Resourceful;
7
use Symfony\Component\HttpFoundation\JsonResponse;
8
use Symfony\Component\HttpFoundation\Request;
9
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
10
use Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException;
11
12
class GetResourceController
13
{
14
    private $service;
15
    private $contentType;
16
17 12
    public function __construct(Cache $service, $contentType = "application/json")
18
    {
19 12
        $this->service = $service;
20 12
        $this->contentType = $contentType;
21 12
    }
22
23 9
    public function __invoke(Resourceful $app, Request $request)
24
    {
25 9
        if (!$this->service->contains($request->getRequestUri())) {
26 3
            throw new NotFoundHttpException("Not Found");
27
        }
28
29 6
        $resource = $this->service->fetch($request->getRequestUri());
30 6
        if ($resource === false) {
31 1
            throw new ServiceUnavailableHttpException(null, "Failed to retrieve resource");
32
        }
33
34 5
        $response = JsonResponse::create($resource);
35 5
        $response->headers->set("Content-Type", $this->contentType);
36
37 5
        return $app["allow"]($request, $response, $app);
38
    }
39
}
40