Passed
Push — master ( f137da...c4f5b9 )
by Petr
03:20
created

User   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 159
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 3

Test Coverage

Coverage 80%

Importance

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

10 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 20 3
A getRoles() 0 9 1
A setVkToken() 0 4 1
A updateToken() 0 4 1
A getPassword() 0 1 1
A getSalt() 0 1 1
A eraseCredentials() 0 1 1
A getUsername() 0 4 1
A getToken() 0 4 1
A getName() 0 4 1
1
<?php
2
3
namespace AppBundle\Entity;
4
5
use AppBundle\Entity\Infrasctucture\FormattedRegistrationDateTrait;
6
use AppBundle\Service\HashGenerator;
7
use Doctrine\Common\Collections\ArrayCollection;
8
use Doctrine\ORM\Mapping as ORM;
9
use JMS\Serializer\Annotation as Serializer;
10
use JMS\Serializer\Annotation\Accessor;
11
use JMS\Serializer\Annotation\SerializedName;
12
use JMS\Serializer\Annotation\Type as SerializerType;
13
use Symfony\Component\Security\Core\User\UserInterface;
14
15
/**
16
 * User
17
 * @ORM\Table(name="users")
18
 * @ORM\Entity(repositoryClass="AppBundle\Entity\Repository\UserRepository")
19
 */
20
class User implements UserInterface
21
{
22
23
    use FormattedRegistrationDateTrait;
24
25
    const TOKEN_LENGTH = 32;
26
27
    /**
28
     * @var string
29
     * @ORM\Id
30
     * @ORM\Column(name="login", type="string", length=255, nullable=false)
31
     */
32
    private $login;
33
34
    /**
35
     * @var string
36
     * @ORM\Column(name="name", type="string", length=255, nullable=false, unique=true)
37
     */
38
    private $name;
39
40
    /**
41
     * @var string
42
     * @ORM\Column(name="email", type="string", length=255, nullable=true, unique=true)
43
     * @Serializer\Exclude()
44
     */
45
    private $email;
46
47
    /**
48
     * @var string
49
     * @ORM\Column(name="description", type="text", nullable=true)
50
     */
51
    private $description;
52
53
    /**
54
     * @var string
55
     * @ORM\Column(name="vkontakte_id", type="string", length=50, nullable=false, unique=true)
56
     * @Serializer\Exclude()
57
     */
58
    private $vkontakteId;
59
60
    /**
61
     * @var string
62
     * @ORM\Column(name="vk_token", type="string", length=85, nullable=false)
63
     * @Serializer\Exclude()
64
     */
65
    private $vkToken;
66
67
    /**
68
     * @var string
69
     * @ORM\Column(name="token", type="string", length=32, nullable=false, unique=true)
70
     * @Serializer\Exclude()
71
     */
72
    private $token;
73
74
    /**
75
     * @var \DateTime
76
     * @ORM\Column(name="registration_date", type="datetime", nullable=false)
77
     * @SerializedName("registration_date")
78
     * @Accessor(getter="getRegistrationDate")
79
     * @SerializerType("string")
80
     */
81
    private $registrationDate;
82
83
    /**
84
     * @var array
85
     * @ORM\Column(name="roles", type="simple_array", nullable=true)
86
     * @Serializer\Exclude()
87
     */
88
    private $roles;
89
90
    /**
91
     * @var Event[]|ArrayCollection
92
     * @ORM\OneToMany(targetEntity="AppBundle\Entity\Event", mappedBy="creator")
93
     * @SerializerType("array")
94
     */
95
    private $events;
96
97
    /**
98
     * @var Band[]|ArrayCollection
99
     * @ORM\OneToMany(targetEntity="AppBundle\Entity\Band", mappedBy="creator")
100
     * @SerializerType("array")
101
     */
102
    private $createdBands;
103
104 4
    public function __construct(
105
        string $login,
106
        string $name,
107
        int $vkontakteId,
108
        string $vkToken,
109
        string $email = null,
110
        string $description = null,
111
        string $token = null
112
    ) {
113 4
        $this->login = $login;
114 4
        $this->name = $name;
115 4
        $this->vkontakteId = $vkontakteId;
0 ignored issues
show
Documentation Bug introduced by
The property $vkontakteId was declared of type string, but $vkontakteId is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
116 4
        $this->vkToken = $vkToken;
117 4
        $this->token = $token ?: HashGenerator::generate(self::TOKEN_LENGTH);
118 4
        $this->email = $email ?: null;
119 4
        $this->description = $description;
120 4
        $this->registrationDate = new \DateTime();
121 4
        $this->events = new ArrayCollection();
122 4
        $this->createdBands = new ArrayCollection();
123 4
    }
124
125
    /**
126
     * @return string
127
     */
128 25
    public function getLogin(): string
129
    {
130 25
        return $this->login;
131
    }
132
133
    /** {@inheritDoc} */
134 24
    public function getRoles(): array
135
    {
136 24
        return array_merge(
137 24
            $this->roles,
138
            [
139 24
                'ROLE_USER',
140
            ]
141
        );
142
    }
143
144
    public function setVkToken(string $vkToken)
145
    {
146
        $this->vkToken = $vkToken;
147
    }
148
149
    public function updateToken()
150
    {
151
        $this->token = HashGenerator::generate(self::TOKEN_LENGTH);
152
    }
153
154 1
    public function getToken(): string
155
    {
156 1
        return $this->token;
157
    }
158
159
    /** {@inheritDoc} */
160
    public function getPassword() {}
161
162
    /** {@inheritDoc} */
163
    public function getSalt() {}
164
165
    /** {@inheritDoc} */
166
    public function eraseCredentials() {}
167
168
    /** {@inheritDoc} */
169 25
    public function getUsername(): string
170
    {
171 25
        return $this->getLogin();
172
    }
173
174 1
    public function getName(): string
175
    {
176 1
        return $this->name;
177
    }
178
}
179