Passed
Push — develop ( 2fff64...5f0aa7 )
by Septianata
04:06
created

RouteServiceProvider::boot()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 1.0004

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 17
ccs 12
cts 13
cp 0.9231
rs 9.8666
cc 1
nc 1
nop 0
crap 1.0004
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 = '/';
21
22
    /**
23
     * The controller namespace for the application.
24
     *
25
     * When present, controller route declarations will automatically be prefixed with this namespace.
26
     *
27
     * @var string|null
28
     */
29
    // protected $namespace = 'App\\Http\\Controllers';
30
31
    /**
32
     * Define your route model bindings, pattern filters, etc.
33
     *
34
     * @return void
35
     */
36 18
    public function boot()
37
    {
38 18
        $this->configureRateLimiting();
39
40 18
        $this->routes(function () {
41 18
            Route::prefix('api')
42 18
                ->middleware('api')
43 18
                ->namespace($this->namespace)
44 18
                ->group(base_path('routes/api.php'));
45
46 18
            Route::middleware('web')
47 18
                ->namespace($this->namespace)
48 18
                ->group(base_path('routes/web.php'));
49
50 18
            Route::match(['get', 'post'], '/botman', function () {
51
                $this->mapBotManCommands();
52 18
            })->middleware('web_without_csrf');
53 18
        });
54 18
    }
55
56
    /**
57
     * Configure the rate limiters for the application.
58
     *
59
     * @return void
60
     */
61 18
    protected function configureRateLimiting()
62
    {
63 18
        RateLimiter::for('api', function (Request $request) {
64
            return Limit::perMinute(60)->by(optional($request->user())->id ?: $request->ip());
65 18
        });
66 18
    }
67
68
    /**
69
     * Defines the BotMan "hears" commands.
70
     *
71
     * Note: Please don't remove this below file, as it will be used also on the artisan command `botman:tinker`
72
     *
73
     * @return void
74
     */
75
    protected function mapBotManCommands()
76
    {
77
        require base_path('routes/botman.php');
78
    }
79
}
80