RouteServiceProvider   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Test Coverage

Coverage 92.31%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 48
ccs 12
cts 13
cp 0.9231
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 13 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
     * This is used by Laravel authentication to redirect users after login.
17
     *
18
     * @var string
19
     */
20
    public const HOME = '/home';
21
22
    /**
23
     * {@inheritDoc}
24
     *
25
     * When present, controller route declarations will automatically be prefixed with this namespace.
26
     */
27
    // protected $namespace = 'App\\Http\\Controllers';
28
29
    /**
30
     * Define your route model bindings, pattern filters, etc.
31
     *
32
     * @return void
33
     */
34 1
    public function boot()
35
    {
36 1
        $this->configureRateLimiting();
37
38 1
        $this->routes(function () {
39 1
            Route::prefix('api')
40 1
                ->middleware('api')
41 1
                ->namespace($this->namespace)
42 1
                ->group(base_path('routes/api.php'));
43
44 1
            Route::middleware('web')
45 1
                ->namespace($this->namespace)
46 1
                ->group(base_path('routes/web.php'));
47
        });
48
    }
49
50
    /**
51
     * Configure the rate limiters for the application.
52
     *
53
     * @return void
54
     */
55 1
    protected function configureRateLimiting()
56
    {
57 1
        RateLimiter::for('api', function (Request $request) {
58
            return Limit::perMinute(60)->by(optional($request->user())->id ?: $request->ip());
59
        });
60
    }
61
}
62