Passed
Push — master ( a532fe...5ccf6a )
by Petr
03:21
created

User   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 154
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 2

Test Coverage

Coverage 80%

Importance

Changes 0
Metric Value
wmc 13
lcom 3
cbo 2
dl 0
loc 154
ccs 24
cts 30
cp 0.8
rs 10
c 0
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A getSalt() 0 1 1
A eraseCredentials() 0 1 1
A __construct() 0 20 3
A getRoles() 0 9 1
A setVkToken() 0 4 1
A updateToken() 0 4 1
A getToken() 0 4 1
A getPassword() 0 1 1
A getUsername() 0 4 1
A getName() 0 4 1
1
<?php
2
3
namespace AppBundle\Entity;
4
5
use AppBundle\Service\HashGenerator;
6
use Doctrine\Common\Collections\ArrayCollection;
7
use Doctrine\ORM\Mapping as ORM;
8
use JMS\Serializer\Annotation as Serializer;
9
use JMS\Serializer\Annotation\Type as SerializerType;
10
use Symfony\Component\Security\Core\User\UserInterface;
11
12
/**
13
 * User
14
 * @ORM\Table(name="users")
15
 * @ORM\Entity(repositoryClass="AppBundle\Entity\Repository\UserRepository")
16
 */
17
class User implements UserInterface
18
{
19
20
    const TOKEN_LENGTH = 32;
21
22
    /**
23
     * @var string
24
     * @ORM\Id
25
     * @ORM\Column(name="login", type="string", length=255, nullable=false)
26
     */
27
    private $login;
28
29
    /**
30
     * @var string
31
     * @ORM\Column(name="name", type="string", length=255, nullable=false, unique=true)
32
     */
33
    private $name;
34
35
    /**
36
     * @var string
37
     * @ORM\Column(name="email", type="string", length=255, nullable=true, unique=true)
38
     * @Serializer\Exclude()
39
     */
40
    private $email;
41
42
    /**
43
     * @var string
44
     * @ORM\Column(name="description", type="text", nullable=true)
45
     */
46
    private $description;
47
48
    /**
49
     * @var int
50
     * @ORM\Column(name="vkontakte_id", type="integer", nullable=false, unique=true)
51
     * @Serializer\Exclude()
52
     */
53
    private $vkontakteId;
54
55
    /**
56
     * @var string
57
     * @ORM\Column(name="vk_token", type="string", length=85, nullable=false)
58
     * @Serializer\Exclude()
59
     */
60
    private $vkToken;
61
62
    /**
63
     * @var string
64
     * @ORM\Column(name="token", type="string", length=32, nullable=false, unique=true)
65
     * @Serializer\Exclude()
66
     */
67
    private $token;
68
69
    /**
70
     * @var \DateTime
71
     * @ORM\Column(name="registration_date", type="datetime", nullable=false)
72
     */
73
    private $registrationDate;
74
75
    /**
76
     * @var array
77
     * @ORM\Column(name="roles", type="simple_array", nullable=true)
78
     * @Serializer\Exclude()
79
     */
80
    private $roles;
81
82
    /**
83
     * @var Event[]|ArrayCollection
84
     * @ORM\OneToMany(targetEntity="AppBundle\Entity\Event", mappedBy="creator")
85
     * @SerializerType("array")
86
     */
87
    private $events;
88
89
    /**
90
     * @var Band[]|ArrayCollection
91
     * @ORM\OneToMany(targetEntity="AppBundle\Entity\Band", mappedBy="creator")
92
     * @SerializerType("array")
93
     */
94
    private $createdBands;
95
96 4
    public function __construct(
97
        string $login,
98
        string $name,
99
        int $vkontakteId,
100
        string $vkToken,
101
        string $email = null,
102
        string $description = null,
103
        string $token = null
104
    ) {
105 4
        $this->login = $login;
106 4
        $this->name = $name;
107 4
        $this->vkontakteId = $vkontakteId;
108 4
        $this->vkToken = $vkToken;
109 4
        $this->token = $token ?: HashGenerator::generate(self::TOKEN_LENGTH);
110 4
        $this->email = $email ?: null;
111 4
        $this->description = $description;
112 4
        $this->registrationDate = new \DateTime();
113 4
        $this->events = new ArrayCollection();
114 4
        $this->createdBands = new ArrayCollection();
115 4
    }
116
117
    /**
118
     * @return string
119
     */
120 37
    public function getLogin(): string
121
    {
122 37
        return $this->login;
123
    }
124
125
    /** {@inheritDoc} */
126 36
    public function getRoles(): array
127
    {
128 36
        return array_merge(
129 36
            $this->roles,
130
            [
131 36
                'ROLE_USER',
132
            ]
133
        );
134
    }
135
136
    public function setVkToken(string $vkToken)
137
    {
138
        $this->vkToken = $vkToken;
139
    }
140
141
    public function updateToken()
142
    {
143
        $this->token = HashGenerator::generate(self::TOKEN_LENGTH);
144
    }
145
146 1
    public function getToken(): string
147
    {
148 1
        return $this->token;
149
    }
150
151
    /** {@inheritDoc} */
152
    public function getPassword() {}
153
154
    /** {@inheritDoc} */
155
    public function getSalt() {}
156
157
    /** {@inheritDoc} */
158
    public function eraseCredentials() {}
159
160
    /** {@inheritDoc} */
161 37
    public function getUsername(): string
162
    {
163 37
        return $this->getLogin();
164
    }
165
166 1
    public function getName(): string
167
    {
168 1
        return $this->name;
169
    }
170
}
171