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

FloodGate   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 1
dl 0
loc 23
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A isFlooding() 0 12 1
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