ApiToken::getId()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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