FloodGate::isFlooding()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 8
nc 1
nop 1
dl 0
loc 12
rs 10
c 1
b 0
f 0
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