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.

IndexControllerProvider::connect()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2.004

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 9.6
c 0
b 0
f 0
cc 2
nc 1
nop 1
ccs 9
cts 10
cp 0.9
crap 2.004
1
<?php
2
3
namespace JDesrosiers\Resourceful\IndexControllerProvider;
4
5
use Doctrine\Common\Cache\Cache;
6
use JDesrosiers\Resourceful\Controller\GetResourceController;
7
use JDesrosiers\Resourceful\ResourcefulServiceProvider\AddSchema;
8
use Silex\Api\ControllerProviderInterface;
9
use Silex\Application;
10
use Symfony\Component\HttpFoundation\Request;
11
use Twig_Loader_Filesystem;
12
13
class IndexControllerProvider implements ControllerProviderInterface
14
{
15
    private $service;
16
17 1
    public function __construct(Cache $service)
18
    {
19 1
        $this->service = $service;
20 1
    }
21
22 1
    public function connect(Application $app)
23
    {
24 1
        $schema = $app["url_generator"]->generate("schema", ["type" => "index"]);
25 1
        $resource = $app["resources_factory"]($schema);
26
27 1
        $app["twig.loader"]->addLoader(new Twig_Loader_Filesystem(__DIR__ . "/templates"));
28 1
        $app->before(new AddSchema($schema, "index"));
29
30
        // Generate default Index resource
31 1
        $resource->before(function (Request $request, Application $app) {
32 1
            $index = $app["url_generator"]->generate("index");
33 1
            if (!$this->service->contains($index)) {
34
                $this->service->save($index, json_decode($app["twig"]->render("default.json.twig")));
35
            }
36 1
        });
37
38
        $resource->get("/", new GetResourceController($this->service))->bind("index");
39
40
        return $resource;
41
    }
42
}
43