UserValidator   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 22
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getColdDownDate() 0 5 1
A isUserColdDown() 0 5 1
A validate() 0 5 2
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