Completed
Push — master ( 1a9043...984777 )
by Valentyn
08:31
created

GuestSession::getToken()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace App\Guests\Entity;
5
6
use App\Users\Entity\User;
7
use Doctrine\ORM\Mapping as ORM;
8
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
9
10
/**
11
 * @ORM\Entity(repositoryClass="App\Guests\Repository\GuestRepository")
12
 * @ORM\Table(name="guest_sessions")
13
 * @UniqueEntity(fields="token", message="This token already taken")
14
 */
15
class GuestSession
16
{
17
    /**
18
     * @ORM\Id()
19
     * @ORM\GeneratedValue()
20
     * @ORM\Column(type="integer")
21
     */
22
    private $id;
23
24
    /**
25
     * @ORM\Column(type="string", length=256, unique=true)
26
     */
27
    private $token;
28
29
    /**
30
     * @var \DateTimeInterface
31
     * @ORM\Column(type="date")
32
     */
33
    private $expiresAt;
34
35
    /**
36
     * GuestSession constructor.
37
     * @throws \Exception
38
     */
39 1
    public function __construct()
40
    {
41 1
        $this->token = bin2hex(openssl_random_pseudo_bytes(32));
42 1
        $this->expiresAt = new \DateTimeImmutable('+1 week');
43 1
    }
44
45 1
    public function getId()
46
    {
47 1
        return $this->id;
48
    }
49
50 2
    public function getToken(): string
51
    {
52 2
        return $this->token;
53
    }
54
}