Test Setup Failed
Push — master ( ca9897...8a7fbb )
by he
14:15 queued 06:25
created

UserValidator::isUserColdDown()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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