FloodGate   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
dl 0
loc 21
rs 10
c 1
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A isFlooding() 0 12 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Xetaravel\Models\Gates;
6
7
use Carbon\Carbon;
8
use Illuminate\Support\Facades\Auth;
9
10
trait FloodGate
11
{
12
    /**
13
     * Check whatever the user is flooding or not.
14
     *
15
     * @param string $rule The configuration rule to use.
16
     *
17
     * @return bool
18
     */
19
    public static function isFlooding(string $rule = 'xetaravel.flood.general'): bool
20
    {
21
        $class = get_called_class();
22
        $user = Auth::user();
23
24
        return $class::where('user_id', $user->id)
0 ignored issues
show
Bug introduced by
Accessing id on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
25
            ->where(
26
                'created_at',
27
                '>=',
28
                Carbon::now()->subSeconds(config($rule))
29
            )
30
            ->exists();
31
    }
32
}
33