Completed
Pull Request — master (#18)
by Valentyn
02:52
created

ApiToken::getUser()   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\Entity;
5
6
use Doctrine\ORM\Mapping as ORM;
7
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
8
9
/**
10
 * @ORM\Entity(repositoryClass="App\Repository\ApiTokenRepository")
11
 * @ORM\Table(name="users_api_tokens")
12
 * @UniqueEntity(fields="token", message="This token already taken")
13
 */
14
class ApiToken
15
{
16
    /**
17
     * @ORM\Id()
18
     * @ORM\GeneratedValue()
19
     * @ORM\Column(type="integer")
20
     */
21
    private $id;
22
23
    /**
24
     * @var $user User
25
     * @ORM\ManyToOne(targetEntity="App\Entity\User")
26
     */
27
    private $user;
28
29
    /**
30
     * @ORM\Column(type="string", length=256, unique=true)
31
     */
32
    private $token;
33
34 4
    public function __construct(User $user)
35
    {
36 4
        $this->token = bin2hex(openssl_random_pseudo_bytes(128));
37
        #$user->addApiToken($this);
0 ignored issues
show
Unused Code Comprehensibility introduced by
86% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
38 4
        $this->user = $user;
39 4
    }
40
41
    public function getId()
42
    {
43
        return $this->id;
44
    }
45
46 2
    public function getUser(): User
47
    {
48 2
        return $this->user;
49
    }
50
51 4
    public function getToken(): string
52
    {
53 4
        return $this->token;
54
    }
55
}