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

ThrottleRequests   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 7 2
A isEnabled() 0 3 1
A __construct() 0 5 1
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