RouteServiceProvider   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 82
rs 10
wmc 7
lcom 2
cbo 2

3 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 6 1
A registerMacros() 0 13 2
A map() 0 56 4
1
<?php
2
3
namespace App\Providers;
4
5
use Auth;
6
use Route;
7
use Exception;
8
use Illuminate\Routing\Router;
9
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
10
11
class RouteServiceProvider extends ServiceProvider
12
{
13
    protected $namespace = \App\Http\Controllers::class;
14
15
    public function boot()
16
    {
17
        $this->registerMacros(app(\Illuminate\Routing\Router::class));
18
19
        parent::boot();
20
    }
21
22
    protected function registerMacros(Router $router)
23
    {
24
        $router->macro('module', function ($module, $sortable = false) use ($router) {
25
            $controller = ucfirst($module).'Controller';
26
            if ($sortable) {
27
                $router->patch("{$module}/changeOrder", $controller.'@changeOrder');
28
            }
29
30
            $router->resource($module, $controller);
31
        });
32
33
        $this->app['paginateroute']->registerMacros();
34
    }
35
36
    public function map(Router $router)
0 ignored issues
show
Unused Code introduced by
The parameter $router is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
37
    {
38
        Route::group(['namespace' => $this->namespace], function () {
39
40
            /*
41
             * Special routes
42
             */
43
            Route::group(['middleware' => 'web'], function () {
44
                Route::demoAccess('/demo');
45
46
                Route::get('coming-soon', function () {
47
                    return view('temp/index');
48
                });
49
            });
50
51
            /*
52
             * Back site
53
             */
54
            Route::group(['namespace' => 'Back', 'middleware' => 'web', 'prefix' => 'blender'], function () {
55
                Auth::routes();
56
57
                Route::group(['middleware' => 'auth'], function () {
58
                    require base_path('routes/back.php');
59
                });
60
            });
61
62
            /*
63
             * Frontsite
64
             */
65
66
            Route::group(['namespace' => 'Front'], function () {
67
                Route::group(['namespace' => 'Api', 'middleware' => 'api', 'prefix' => 'api'], function () {
68
                    require base_path('routes/frontApi.php');
69
                });
70
71
                Route::group(['middleware' => ['web', 'demoMode', 'rememberLocale']], function () {
72
                    $multiLingual = count(config('app.locales')) > 1;
73
74
                    Route::group($multiLingual ? ['prefix' => locale()] : [], function () {
75
                        try {
76
                            Auth::routes();
77
                            require base_path('routes/front.php');
78
                        } catch (Exception $exception) {
79
                            logger()->warning("Front routes weren't included because {$exception->getMessage()}.");
80
                        }
81
                    });
82
83
                    if ($multiLingual) {
84
                        Route::get('/', function () {
85
                            return redirect(locale());
86
                        });
87
                    }
88
                });
89
            });
90
        });
91
    }
92
}
93