Test Setup Failed
Push — master ( 72a408...3f5e9b )
by Alexey
02:46
created

User::addSubscriber()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
ccs 0
cts 2
cp 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Skobkin\Bundle\PointToolsBundle\Entity;
4
5
use Doctrine\Common\Collections\ArrayCollection;
6
use Doctrine\ORM\Mapping as ORM;
7
8
/**
9
 * @ORM\Table(name="users", schema="users")
10
 * @ORM\Entity(repositoryClass="Skobkin\Bundle\PointToolsBundle\Repository\UserRepository")
11
 * @ORM\HasLifecycleCallbacks
12
 */
13
class User
14
{
15
    const AVATAR_SIZE_SMALL = '24';
16
    const AVATAR_SIZE_MEDIUM = '40';
17
    const AVATAR_SIZE_LARGE = '80';
18
19
    /**
20
     * @var int
21
     *
22
     * @ORM\Column(name="id", type="integer")
23
     * @ORM\Id
24
     */
25
    private $id;
26
27
    /**
28
     * @var string
29
     *
30
     * @ORM\Column(name="login", type="string", length=255, nullable=false)
31
     */
32
    private $login;
33
34
    /**
35
     * @var string|null
36
     *
37
     * @ORM\Column(name="name", type="string", length=255, nullable=true)
38
     */
39
    private $name;
40
41
    /**
42
     * @var \DateTime
43
     *
44
     * @ORM\Column(name="created_at", type="datetime")
45
     */
46
    private $createdAt;
47
48
    /**
49
     * @var \DateTime
50
     *
51
     * @ORM\Column(name="updated_at", type="datetime", nullable=true)
52
     */
53
    private $updatedAt;
54
55
    /**
56
     * @var ArrayCollection|Subscription[]
57
     *
58
     * @ORM\OneToMany(targetEntity="Subscription", mappedBy="author", fetch="EXTRA_LAZY")
59
     */
60
    private $subscribers;
61
62
    /**
63
     * @var ArrayCollection|Subscription[]
64
     *
65
     * @ORM\OneToMany(targetEntity="Subscription", mappedBy="subscriber", fetch="EXTRA_LAZY")
66
     */
67
    private $subscriptions;
68
69
    /**
70
     * @var ArrayCollection|SubscriptionEvent[]
71
     * @ORM\OneToMany(targetEntity="SubscriptionEvent", mappedBy="author", fetch="EXTRA_LAZY")
72
     */
73
    private $newSubscriberEvents;
74
75
76
    public function __construct(int $id, string $login = null, string $name = null)
77
    {
78
        $this->id = $id;
79
        $this->login = $login;
80
        $this->name = $name;
81
        $this->createdAt = new \DateTime();
82
83
        $this->subscribers = new ArrayCollection();
84
        $this->subscriptions = new ArrayCollection();
85
        $this->newSubscriberEvents = new ArrayCollection();
86
    }
87
88
    /**
89
     * @ORM\PreUpdate
90
     */
91
    public function preUpdate(): void
92
    {
93
        $this->updatedAt = new \DateTime();
94
    }
95
96
    public function getId(): int
97
    {
98
        return $this->id;
99
    }
100
101
    public function setLogin(string $login): self
102
    {
103
        $this->login = $login;
104
105
        return $this;
106 3
    }
107
108 3
    public function getLogin(): string
109
    {
110
        return $this->login;
111
    }
112
113
    public function setName(?string $name): self
114
    {
115
        $this->name = $name;
116
117
        return $this;
118
    }
119
120
    public function getName(): ?string
121
    {
122 7
        return $this->name;
123
    }
124 7
125
    public function addSubscriber(Subscription $subscribers): self
126
    {
127
        $this->subscribers[] = $subscribers;
128
129
        return $this;
130
    }
131
132
    public function removeSubscriber(Subscription $subscribers)
133
    {
134 1
        $this->subscribers->removeElement($subscribers);
135
    }
136 1
137
    /**
138
     * @return Subscription[]|ArrayCollection
139
     */
140
    public function getSubscribers()
141
    {
142
        return $this->subscribers;
143
    }
144
145
    /**
146
     * @return Subscription[]|ArrayCollection
147
     */
148
    public function getSubscriptions()
149
    {
150
        return $this->subscriptions;
151
    }
152
153
    public function addNewSubscriberEvent(SubscriptionEvent $newSubscriberEvents): self
154
    {
155
        $this->newSubscriberEvents[] = $newSubscriberEvents;
156
157
        return $this;
158
    }
159
160
    /**
161
     * @return SubscriptionEvent[]|ArrayCollection
162
     */
163
    public function getNewSubscriberEvents()
164
    {
165
        return $this->newSubscriberEvents;
166
    }
167
168
    public function getCreatedAt(): \DateTime
169
    {
170
        return $this->createdAt;
171
    }
172
173
    public function setCreatedAt(\DateTime $createdAt): self
174
    {
175
        $this->createdAt = $createdAt;
176
177
        return $this;
178
    }
179
180
    public function getUpdatedAt(): ?\DateTime
181
    {
182
        return $this->updatedAt;
183
    }
184
}
185