RouteServiceProvider   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 93.75%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 49
ccs 15
cts 16
cp 0.9375
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 16 1
A configureRateLimiting() 0 4 2
1
<?php
2
3
namespace App\Providers;
4
5
use Illuminate\Cache\RateLimiting\Limit;
6
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
7
use Illuminate\Http\Request;
8
use Illuminate\Support\Facades\RateLimiter;
9
use Illuminate\Support\Facades\Route;
10
11
class RouteServiceProvider extends ServiceProvider
12
{
13
    /**
14
     * The path to the "home" route for your application.
15
     *
16
     * Typically, users are redirected here after authentication.
17
     *
18
     * @var string
19
     */
20
    public const HOME = '/dashboard';
21
22
    /**
23
     * The path to the "home" route for your application.
24
     *
25
     * Typically, admins are redirected here after authentication.
26
     *
27
     * @var string
28
     */
29
    public const ADMIN_HOME = '/admin';
30
31
    /**
32
     * Define your route model bindings, pattern filters, and other route configuration.
33
     */
34 75
    public function boot(): void
35
    {
36 75
        $this->configureRateLimiting();
37
38 75
        $this->routes(function () {
39 75
            Route::middleware('api')
40 75
                ->prefix('api')
41 75
                ->group(base_path('routes/api.php'));
42
43 75
            Route::middleware('web')
44 75
                ->group(base_path('routes/web.php'));
45
46 75
            Route::prefix('admin')
47 75
                ->as('admin.')
48 75
                ->middleware('web')
49 75
                ->group(base_path('routes/admin.php'));
50 75
        });
51
    }
52
53
    /**
54
     * Configure the rate limiters for the application.
55
     */
56 75
    protected function configureRateLimiting(): void
57
    {
58 75
        RateLimiter::for('api', function (Request $request) {
59
            return Limit::perMinute(60)->by($request->user()?->id ?: $request->ip());
60 75
        });
61
    }
62
}
63