Test Setup Failed
Push — master ( 584547...730ac2 )
by Alexey
14:04
created

Account::updateFromMessageData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 0
cts 4
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 4
crap 2
1
<?php
2
3
namespace Skobkin\Bundle\PointToolsBundle\Entity\Telegram;
4
5
use Doctrine\ORM\Mapping as ORM;
6
use Skobkin\Bundle\PointToolsBundle\Entity\User;
7
8
/**
9
 * @ORM\Table(name="telegram_accounts", schema="users", indexes={
10
 *      @ORM\Index(name="subscriber_notification_idx", columns={"subscriber_notification"}, options={"where": "subscriber_notification = TRUE"}),
11
 *      @ORM\Index(name="rename_notification_idx", columns={"rename_notification"}, options={"where": "rename_notification = TRUE"}),
12
 * })
13
 * @ORM\Entity(repositoryClass="Skobkin\Bundle\PointToolsBundle\Repository\Telegram\AccountRepository")
14
 * @ORM\HasLifecycleCallbacks()
15
 */
16
class Account
17
{
18
    /**
19
     * Telegram user ID
20
     *
21
     * @var int
22
     *
23
     * @ORM\Id()
24
     * @ORM\Column(name="account_id", type="integer")
25
     */
26
    private $id;
27
28
    /**
29
     * @var \DateTime
30
     *
31
     * @ORM\Column(name="created_at", type="datetime")
32
     */
33
    private $createdAt;
34
35
    /**
36
     * @var \DateTime
37
     *
38
     * @ORM\Column(name="updated_at", type="datetime", nullable=true)
39
     */
40
    private $updatedAt;
41
42
    /**
43
     * @var \DateTime
44
     *
45
     * @ORM\Column(name="linked_at", type="datetime", nullable=true)
46
     */
47
    private $linkedAt;
48
49
    /**
50
     * @var string
51
     *
52
     * @ORM\Column(name="first_name", type="text")
53
     */
54
    private $firstName;
55
56
    /**
57
     * @var string|null
58
     *
59
     * @ORM\Column(name="last_name", type="text", nullable=true)
60
     */
61
    private $lastName;
62
63
    /**
64
     * @var string|null
65
     *
66
     * @ORM\Column(name="username", type="text", nullable=true)
67
     */
68
    private $username;
69
70
    /**
71
     * ID of private chat with user
72
     *
73
     * @var int
74
     *
75
     * @ORM\Column(name="private_chat_id", type="bigint", nullable=true)
76
     */
77
    private $chatId;
78
79
    /**
80
     * @var User
81
     *
82
     * @ORM\OneToOne(targetEntity="Skobkin\Bundle\PointToolsBundle\Entity\User")
83
     * @ORM\JoinColumn(name="user_id", nullable=true, onDelete="CASCADE")
84
     */
85
    private $user;
86
87
    /**
88
     * Notifications about new subscribers
89
     *
90
     * @var bool
91
     *
92
     * @ORM\Column(name="subscriber_notification", type="boolean")
93
     */
94
    private $subscriberNotification = false;
95
96
    /**
97
     * Notifications about user renaming
98
     *
99
     * @var bool
100
     *
101
     * @ORM\Column(name="rename_notification", type="boolean")
102
     */
103
    private $renameNotification = false;
104
105
106
    public function __construct(int $id)
107
    {
108
        $this->id = $id;
109
        $this->createdAt = new \DateTime();
110
    }
111
112
    /**
113
     * @ORM\PreUpdate()
114
     */
115
    public function preUpdate(): void
116
    {
117
        $this->updatedAt = new \DateTime();
118
    }
119
120
    public function getId(): int
121
    {
122
        return $this->id;
123
    }
124
125
    public function getCreatedAt(): \DateTime
126
    {
127
        return $this->createdAt;
128
    }
129
130
    public function getUpdatedAt(): \DateTime
131
    {
132
        return $this->updatedAt;
133
    }
134
135
    public function getLinkedAt(): \DateTime
136
    {
137
        return $this->linkedAt;
138
    }
139
140
    public function getFirstName(): string
141
    {
142
        return $this->firstName;
143
    }
144
145
    public function updateFromMessageData(string $firstName, ?string $lastName, ?string $username, int $chatId): void
146
    {
147
        $this->firstName = $firstName;
148
        $this->lastName = $lastName;
149
        $this->username = $username;
150
        $this->chatId = $chatId;
151
    }
152
153
    public function getLastName(): ?string
154
    {
155
        return $this->lastName;
156
    }
157
158
    public function getUsername(): string
159
    {
160
        return $this->username;
161
    }
162
163
    public function getChatId(): int
164
    {
165
        return $this->chatId;
166
    }
167
168
    public function getUser(): ?User
169
    {
170
        return $this->user;
171
    }
172
173
    public function setUser(User $user): Account
174
    {
175
        if (!$this->user && $user) {
176
            $this->linkedAt = new \DateTime();
177
        }
178
179
        $this->user = $user;
180
181
        return $this;
182
    }
183
184
    public function getUserId(): int
185
    {
186
        return $this->user->getId();
187
    }
188
189
    public function disableNotifications(): self
190
    {
191
        $this->subscriberNotification = false;
192
        $this->renameNotification = false;
193
194
        return $this;
195
    }
196
197
    public function setSubscriberNotification(bool $subscriberNotification): self
198
    {
199
        $this->subscriberNotification = $subscriberNotification;
200
201
        return $this;
202
    }
203
204
    public function toggleSubscriberNotification(): self
205
    {
206
        $this->subscriberNotification = !$this->subscriberNotification;
207
208
        return $this;
209
    }
210
211
    public function isSubscriberNotification(): bool
212
    {
213
        return $this->subscriberNotification;
214
    }
215
216
    public function setRenameNotification(bool $renameNotification): self
217
    {
218
        $this->renameNotification = $renameNotification;
219
220
        return $this;
221
    }
222
223
    public function toggleRenameNotification(): self
224
    {
225
        $this->renameNotification = !$this->renameNotification;
226
227
        return $this;
228
    }
229
230
    public function isRenameNotification(): bool
231
    {
232
        return $this->renameNotification;
233
    }
234
}
235