Test Setup Failed
Push — develop ( 82cf6b...198473 )
by Stone
06:50 queued 11s
created

RegistrationSetHash::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Services\Registration;
4
5
6
use App\Entity\User;
7
use Doctrine\ORM\EntityManagerInterface;
8
9
class RegistrationSetHash
10
{
11
    /**
12
     * @var EntityManagerInterface
13
     */
14
    private $em;
15
16
    public function __construct(EntityManagerInterface $em)
17
    {
18
        $this->em = $em;
19
    }
20
21
    /**
22
     * @param User $user
23
     * @return string
24
     * @throws \Exception
25
     * Sets a new hash to the verifiedDateTimeField of the passed user
26
     */
27
    public function setHash(User $user): string
28
    {
29
        $hash = bin2hex(random_bytes(16));
30
        $user->setVerifiedHash($hash);
31
32
        $user->setVerifiedDateTime(new \DateTime());
33
34
        $this->em->persist($user);
35
        $this->em->flush();
36
        return $hash;
37
    }
38
}