UserValidator::isUserColdDown()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
rs 10
1
<?php
2
3
namespace App\Services\Topic\Validator;
4
5
use App\Entities\User;
6
use App\Exceptions\WebException;
7
use Carbon\Carbon;
8
9
class UserValidator
10
{
11
    public function validate(User $user)
12
    {
13
        $verifiedColdDate = $this->getColdDownDate($user);
14
        if ($verifiedColdDate->gt(Carbon::now())) {
15
            throw new WebException("You can do it after email verified after {$verifiedColdDate}");
16
        }
17
    }
18
19
    public function isUserColdDown(User $user)
20
    {
21
        $verifiedColdDate = $this->getColdDownDate($user);
22
23
        return $verifiedColdDate->lt(Carbon::now());
24
    }
25
26
    public function getColdDownDate(User $user): Carbon
27
    {
28
        $userMustVerifiedAfter = config('hustoj.user.topic.verified_after');
29
30
        return $user->email_verified_at->addHours($userMustVerifiedAfter);
31
    }
32
}
33