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

RegistrationSetHash   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 28
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A setHash() 0 10 1
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
}