Passed
Push — master ( e5d84e...48d24a )
by Koen
10:50
created

ThrottleRequests::handle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 5
dl 0
loc 7
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Http\Middleware;
6
7
use Closure;
8
use Illuminate\Cache\RateLimiter;
9
use Illuminate\Contracts\Config\Repository;
10
11
final class ThrottleRequests extends \Illuminate\Routing\Middleware\ThrottleRequests
12
{
13
    private Repository $config;
14
15
    public function __construct(RateLimiter $limiter, Repository $config)
16
    {
17
        parent::__construct($limiter);
18
19
        $this->config = $config;
20
    }
21
22
    public function handle($request, Closure $next, $maxAttempts = 60, $decayMinutes = 1, $prefix = '')
23
    {
24
        if ($this->isEnabled()) {
25
            return parent::handle($request, $next, $maxAttempts, $decayMinutes, $prefix);
26
        }
27
28
        return $next($request);
29
    }
30
31
    private function isEnabled(): bool
32
    {
33
        return (bool) $this->config->get('app.throttling');
34
    }
35
}
36