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.

RouteServiceProvider   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 106
Duplicated Lines 30.19 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 2
dl 32
loc 106
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A registerMiddleware() 0 20 1
A registerDefinedRoutes() 14 14 1
A registerDefaultRoutes() 18 28 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace LaravelFlare\Flare\Providers\Edge;
4
5
use Illuminate\Routing\Router;
6
use LaravelFlare\Flare\Providers\RouteServiceProvider as AbstractRouteServiceProvider;
7
8
class RouteServiceProvider extends AbstractRouteServiceProvider
9
{
10
    /**
11
     * The compatibility version of this RouteServiceProvider.
12
     * 
13
     * @var string
14
     */
15
    protected $compatibilityVersion = 'Edge';
16
17
    /**
18
     * Register all the Flare Provided Middleware and Middleware Groups.
19
     *
20
     * We define flarebase rather than extend an existing middleware stack
21
     * since it is possible that a user has amended the default middleware 
22
     * of their application in a way that could break Flare.
23
     * 
24
     * @param Router $router
25
     */
26
    protected function registerMiddleware(Router $router)
27
    {
28
        $router->aliasMiddleware('flareauthenticate', \LaravelFlare\Flare\Http\Middleware\FlareAuthenticate::class);
29
        $router->aliasMiddleware('checkmodelfound', \LaravelFlare\Flare\Http\Middleware\CheckModelFound::class);
30
        $router->aliasMiddleware('checkpermissions', \LaravelFlare\Flare\Http\Middleware\CheckPermissions::class);
31
32
        $router->middlewareGroup('flarebase', [
33
                \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
34
                \Illuminate\View\Middleware\ShareErrorsFromSession::class,
35
                \App\Http\Middleware\VerifyCsrfToken::class,
36
                \App\Http\Middleware\EncryptCookies::class,
37
            ]);
38
39
        $router->middlewareGroup('flare', [
40
                'web',
41
                'flarebase',
42
                'flareauthenticate',
43
                'checkpermissions',
44
            ]);
45
    }
46
47
    /**
48
     * Register the Defined Routes.
49
     *
50
     * This registers all the routes which have been defined by
51
     * Admin sections defined in the Application's Flare Config
52
     * (or in the runtime config if anotehr service provider
53
     * has already started manipulating these dynamically).
54
     * 
55
     * @param Router $router
56
     */
57 View Code Duplication
    protected function registerDefinedRoutes(Router $router)
58
    {
59
        $router->group(
60
            [
61
                'prefix' => \Flare::config('admin_url'),
62
                'as' => 'flare::',
63
                'middleware' => ['flare'],
64
            ],
65
            function ($router) {
66
                \Flare::admin()->registerRoutes($router);
67
                $router->get('/', $this->adminController('getDashboard'))->name('dashboard');
68
            }
69
        );
70
    }
71
72
    /**
73
     * Register the Default Routes.
74
     *
75
     * This registers all the default routes which are included
76
     * with Flare. These consist of things which will probably
77
     * be included with every application such as the login,
78
     * logout and password reset forms.
79
     *
80
     * The login form can however be hidden by setting the 
81
     * 'show' config for 'login' to false.
82
     * 
83
     * @param Router $router
84
     */
85
    protected function registerDefaultRoutes(Router $router)
86
    {
87
        $router->group(
88
            [
89
                'prefix' => \Flare::config('admin_url'),
90
                'as' => 'flare::',
91
                'middleware' => ['web', 'flarebase'],
92
            ],
93 View Code Duplication
            function ($router) {
94
                // Logout route...
95
                $router->get('logout', $this->adminController('getLogout'))->name('logout');
96
97
                if (\Flare::show('login')) {
98
                    // Login request reoutes...
99
                    $router->get('login', $this->adminController('getLogin'))->name('login');
100
                    $router->post('login', $this->adminController('postLogin'))->name('login');
101
102
                    // Password reset link request routes...
103
                    $router->get('email', $this->adminController('getEmail'))->name('email');
104
                    $router->post('email', $this->adminController('postEmail'))->name('email');
105
106
                    // Password reset routes...
107
                    $router->get('reset/{token}', $this->adminController('getReset'))->name('reset');
108
                    $router->post('reset', $this->adminController('postReset'))->name('reset');
109
                }
110
            }
111
        );
112
    }
113
}
114