UserSetHash::set()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 8
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Security;
4
5
6
use App\Entity\User;
7
use DateTime;
8
use Exception;
9
10
class UserSetHash
11
{
12
13
    /**
14
     * @param User $user
15
     * @return string
16
     * @throws Exception
17
     * Sets a new hash to the verifiedDateTimeField of the passed user
18
     */
19
    public function set(User $user): string
20
    {
21
        $hash = bin2hex(random_bytes(16));
22
        $user->setVerifiedHash($hash);
23
24
        $user->setVerifiedDateTime(new DateTime());
25
26
        return $hash;
27
    }
28
}