Completed
Pull Request — master (#25)
by Fèvre
05:23 queued 02:34
created

CommentGate::isFlooding()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

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