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
Push — v0 ( 942010...eed4fd )
by Jason
01:28
created

CorsServiceProvider   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 10

Test Coverage

Coverage 92.11%

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 10
dl 0
loc 71
ccs 35
cts 38
cp 0.9211
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 9 3
A register() 0 48 3
1
<?php
2
3
namespace JDesrosiers\Silex\Provider;
4
5
use Silex\Application;
6
use Silex\Controller;
7
use Silex\ServiceProviderInterface;
8
use Symfony\Component\HttpFoundation\Response;
9
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
10
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
11
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
12
use Symfony\Component\HttpKernel\KernelEvents;
13
14
/**
15
 * The CORS service provider provides a `cors` service that a can be included in your project as application middleware.
16
 */
17
class CorsServiceProvider implements ServiceProviderInterface
18
{
19
    /**
20
     * Add OPTIONS method support for all routes
21
     *
22
     * @param Application $app
23
     */
24
    public function boot(Application $app)
25
    {
26 41
        $app->on(KernelEvents::EXCEPTION, function (GetResponseForExceptionEvent $event) {
27 5
            $e = $event->getException();
28 5
            if ($e instanceof MethodNotAllowedHttpException && $e->getHeaders()["Allow"] === "OPTIONS") {
29 1
                $event->setException(new NotFoundHttpException("No route found for \"{$event->getRequest()->getMethod()} {$event->getRequest()->getPathInfo()}\""));
30
            }
31 41
        });
32 41
    }
33
34
    /**
35
     * Register the cors function and set defaults
36
     *
37
     * @param Container $app
38
     */
39 41
    public function register(Application $app)
40
    {
41 41
        $app["cors.allowOrigin"] = "*"; // Defaults to all
42 41
        $app["cors.allowMethods"] = null; // Defaults to all
43 41
        $app["cors.allowHeaders"] = null; // Defaults to all
44 41
        $app["cors.maxAge"] = null;
45 41
        $app["cors.allowCredentials"] = null;
46 41
        $app["cors.exposeHeaders"] = null;
47
48 41
        $app["allow"] = $app->protect(new Allow());
49
50
        $app["options"] = $app->protect(function ($subject) use ($app) {
51 41
            $optionsController = function () {
52 23
                return Response::create("", 204);
53 41
            };
54
55 41
            if ($subject instanceof Controller) {
56 4
                $optionsRoute = $app->match($subject->getRoute()->getPath(), $optionsController)
57 4
                    ->method("OPTIONS")
58 4
                    ->after($app["allow"]);
59
            } else {
60 37
                $optionsRoute = $subject->match("{path}", $optionsController)
61 37
                    ->method("OPTIONS")
62 37
                    ->after($app["allow"])
63 37
                    ->assert("path", ".*");
64
            }
65
66 41
            return $optionsRoute;
67 41
        });
68
69 41
        $app["cors-enabled"] = $app->protect(function ($subject, $config = []) use ($app) {
70 38
            $optionsController = $app["options"]($subject);
71 38
            $cors = new Cors($app, $config);
72
73 38
            if ($subject instanceof Controller) {
74 4
                $optionsController->after($cors);
75
            }
76
77 38
            $subject->after($cors);
78
79 38
            return $subject;
80 41
        });
81
82
        $app["cors"] = function () use ($app) {
83
            $app["options"]($app);
84
            return new Cors();
0 ignored issues
show
Bug introduced by
The call to Cors::__construct() misses a required argument $app.

This check looks for function calls that miss required arguments.

Loading history...
85
        };
86
    }
87
}
88