Passed
Pull Request — main (#29)
by Tan
03:07
created

RouteServiceProvider   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 4
c 1
b 0
f 0
dl 0
loc 15
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 4 1
A configureRateLimiting() 0 4 2
1
<?php
2
3
namespace CSlant\Blog\ApiPackage\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
10
class RouteServiceProvider extends ServiceProvider
11
{
12
    /**
13
     * Move base routes to a service provider to make sure all filters & actions can hook to base routes
14
     */
15
    public function boot(): void
16
    {
17
        // add rate limit for api
18
        $this->configureRateLimiting();
19
    }
20
21
    protected function configureRateLimiting(): void
22
    {
23
        RateLimiter::for((string) config('blog-api.defaults.route_prefix'), function (Request $request) {
24
            return Limit::perMinute(40)->by(optional($request->user())->id ?: $request->ip());
25
        });
26
    }
27
}
28