RouteServiceProvider   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 77
ccs 0
cts 26
cp 0
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A map() 0 11 1
A boot() 0 11 1
A getMiddleware() 0 6 1
A getNamespace() 0 4 1
A requireRoutes() 0 4 1
A register() 0 4 1
1
<?php
2
3
namespace Loadsman\LaravelPlugin\Providers;
4
5
use Loadsman\LaravelPlugin\Http\Middleware\DebugState;
6
use Loadsman\LaravelPlugin\Http\Middleware\DetectRoute;
7
use Loadsman\LaravelPlugin\Http\Middleware\PreventRedirect;
8
use Illuminate\Contracts\Http\Kernel;
9
use Illuminate\Routing\Router;
10
use Illuminate\Support\ServiceProvider;
11
12
class RouteServiceProvider extends ServiceProvider
13
{
14
    /**
15
     * @type \Illuminate\Foundation\Http\Kernel
16
     */
17
    protected $kernel;
18
19
    /**
20
     * Define the routes for the application.
21
     *
22
     * @param  Router $router
23
     *
24
     * @return void
25
     */
26
    public function map(Router $router)
27
    {
28
        $router->group([
29
            'as' => 'api-tester.',
30
            'prefix' => config('api-tester.route'),
31
            'namespace' => $this->getNamespace(),
32
            'middleware' => $this->getMiddleware(),
33
        ], function () {
34
            $this->requireRoutes();
35
        });
36
    }
37
38
    /**
39
     * @param Router $router
40
     * @param Kernel|\Illuminate\Foundation\Http\Kernel $kernel
41
     */
42
    public function boot(Router $router, Kernel $kernel)
43
    {
44
        $this->map($router);
45
46
        $this->kernel = $kernel;
0 ignored issues
show
Documentation Bug introduced by
$kernel is of type object<Illuminate\Contracts\Http\Kernel>, but the property $kernel was declared to be of type object<Illuminate\Foundation\Http\Kernel>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
47
48
        // The middleware is used to intercept every request with specific header
49
        // so that laravel can tell us, which route the request belongs to.
50
        $kernel->prependMiddleware(DetectRoute::class);
51
        $kernel->prependMiddleware(PreventRedirect::class);
52
    }
53
54
    protected function getMiddleware()
55
    {
56
        $middleware = config('api-tester.middleware');
57
58
        return $middleware;
59
    }
60
61
    /**
62
     * Get module namespace
63
     *
64
     * @return string
65
     */
66
    protected function getNamespace()
67
    {
68
        return 'Loadsman\Laravel\Http\Controllers';
69
    }
70
71
    /**
72
     * @return string
73
     */
74
    protected function requireRoutes()
75
    {
76
        require __DIR__ . '/../Http/routes.php';
77
    }
78
79
    /**
80
     * Register the service provider.
81
     *
82
     * @return void
83
     */
84
    public function register()
85
    {
86
87
    }
88
}
89