RoutingServiceProvider   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 95
Duplicated Lines 21.05 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 11
lcom 1
cbo 2
dl 20
loc 95
rs 10
c 1
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 4 1
getFrontendRoute() 0 1 ?
getBackendRoute() 0 1 ?
getApiRoute() 0 1 ?
A loadFrontendRoutes() 0 10 3
A loadBackendRoutes() 10 10 3
A loadApiRoutes() 10 10 3
A map() 0 11 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 namespace Modules\Core\Providers;
2
3
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
4
use Illuminate\Routing\Router;
5
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
6
7
abstract class RoutingServiceProvider extends ServiceProvider
8
{
9
    /**
10
     * The root namespace to assume when generating URLs to actions.
11
     *
12
     * @var string
13
     */
14
    protected $namespace = '';
15
16
    /**
17
     * Define your route model bindings, pattern filters, etc.
18
     *
19
     * @param  \Illuminate\Routing\Router $router
20
     * @return void
21
     */
22
    public function boot(Router $router)
23
    {
24
        parent::boot($router);
25
    }
26
27
    /**
28
     * @return string
29
     */
30
    abstract protected function getFrontendRoute();
31
32
    /**
33
     * @return string
34
     */
35
    abstract protected function getBackendRoute();
36
37
    /**
38
     * @return string
39
     */
40
    abstract protected function getApiRoute();
41
42
    /**
43
     * Define the routes for the application.
44
     *
45
     * @param  \Illuminate\Routing\Router $router
46
     * @return void
47
     */
48
    public function map(Router $router)
49
    {
50
        $router->group(['namespace' => $this->namespace], function (Router $router) {
51
            $this->loadApiRoutes($router);
52
        });
53
54
        $router->group(['namespace' => $this->namespace, 'prefix' => LaravelLocalization::setLocale(), 'middleware' => ['localizationRedirect'] ], function (Router $router) {
55
            $this->loadBackendRoutes($router);
56
            $this->loadFrontendRoutes($router);
57
        });
58
    }
59
60
    /**
61
     * @param Router $router
62
     */
63
    private function loadFrontendRoutes(Router $router)
64
    {
65
        $frontend = $this->getFrontendRoute();
66
67
        if ($frontend && file_exists($frontend)) {
68
            $router->group(['middleware' => config('asgard.core.core.middleware.frontend', [])], function (Router $router) use ($frontend) {
69
                require $frontend;
70
            });
71
        }
72
    }
73
74
    /**
75
     * @param Router $router
76
     */
77 View Code Duplication
    private function loadBackendRoutes(Router $router)
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...
78
    {
79
        $backend = $this->getBackendRoute();
80
81
        if ($backend && file_exists($backend)) {
82
            $router->group(['namespace' => 'Admin', 'prefix' => config('asgard.core.core.admin-prefix'), 'middleware' => config('asgard.core.core.middleware.backend', [])], function (Router $router) use ($backend) {
83
                require $backend;
84
            });
85
        }
86
    }
87
88
    /**
89
     * @param Router $router
90
     */
91 View Code Duplication
    private function loadApiRoutes(Router $router)
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...
92
    {
93
        $api = $this->getApiRoute();
94
95
        if ($api && file_exists($api)) {
96
            $router->group(['namespace' => 'Api', 'prefix' => 'api', 'middleware' => config('asgard.core.core.middleware.api', [])], function (Router $router) use ($api) {
97
                require $api;
98
            });
99
        }
100
    }
101
}
102