Completed
Push — discuss ( 472fcb...21bc4b )
by Fèvre
16:38
created

FloodGate::isFlooding()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 2
1
<?php
2
namespace Xetaravel\Models\Gates;
3
4
use Carbon\Carbon;
5
use Xetaravel\Models\User;
6
7
trait FloodGate
8
{
9
    /**
10
     * Check whatever the user is flooding or not.
11
     *
12
     * @param \Xetaravel\Models\User $user The user to check.
13
     * @param string $rule The configuration rule to use.
14
     *
15
     * @return bool
16
     */
17
    public static function isFlooding(User $user, string $rule = 'xetaravel.flood.general'): bool
18
    {
19
        $class = get_called_class();
20
21
        return $class::where('user_id', $user->id)
22
            ->where(
23
                'created_at',
24
                '>=',
25
                Carbon::now()->subSeconds(config($rule))
26
            )
27
            ->exists();
28
    }
29
}
30