RouteServiceProvider   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 90
Duplicated Lines 22.22 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 20
loc 90
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 6 1
A map() 0 8 1
A mapWebRoutes() 0 9 1
A mapApiRoutes() 10 10 1
A mapJsonApiV1Routes() 10 10 1

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 App\Providers;
4
5
use Illuminate\Support\Facades\Route;
6
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
7
8
class RouteServiceProvider extends ServiceProvider
9
{
10
    /**
11
     * This namespace is applied to your controller routes.
12
     *
13
     * In addition, it is set as the URL generator's root namespace.
14
     *
15
     * @var string
16
     */
17
    protected $namespace = 'App\Http\Controllers';
18
19
    /**
20
     * Define your route model bindings, pattern filters, etc.
21
     *
22
     * @return void
23
     */
24
    public function boot()
25
    {
26
        //
27
28
        parent::boot();
29
    }
30
31
    /**
32
     * Define the routes for the application.
33
     *
34
     * @return void
35
     */
36
    public function map()
37
    {
38
        $this->mapApiRoutes();
39
40
        $this->mapWebRoutes();
41
42
        $this->mapJsonApiV1Routes();
43
    }
44
45
    /**
46
     * Define the "web" routes for the application.
47
     *
48
     * These routes all receive session state, CSRF protection, etc.
49
     *
50
     * @return void
51
     */
52
    protected function mapWebRoutes()
53
    {
54
        Route::group([
55
            'middleware' => 'web',
56
            'namespace' => $this->namespace,
57
        ], function ($router) {
58
            require base_path('routes/web.php');
59
        });
60
    }
61
62
    /**
63
     * Define the "api" routes for the application.
64
     *
65
     * These routes are typically stateless.
66
     *
67
     * @return void
68
     */
69 View Code Duplication
    protected function mapApiRoutes()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
70
    {
71
        Route::group([
72
            'middleware' => 'api',
73
            'namespace' => $this->namespace,
74
            'prefix' => 'api',
75
        ], function ($router) {
76
            require base_path('routes/api.php');
77
        });
78
    }
79
80
    /**
81
     * Define the "api" routes for the application.
82
     *
83
     * These routes are typically stateless.
84
     *
85
     * @return void
86
     */
87 View Code Duplication
    protected function mapJsonApiV1Routes()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
88
    {
89
        Route::group([
90
            'middleware' => 'json-api:v1',
91
            'namespace' => $this->namespace,
92
            'prefix' => 'api/v1'
93
        ], function ($router) {
94
            require base_path('routes/json-api-v1.php');
95
        });
96
    }
97
}
98