Completed
Pull Request — master (#14)
by Matthieu
38:40
created

Notification::addNotificationAttachment()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Yokai\MessengerBundle\Entity;
4
5
use Doctrine\Common\Collections\ArrayCollection;
6
use Doctrine\Common\Util\ClassUtils;
7
use Symfony\Component\HttpFoundation\File\File;
8
use Yokai\MessengerBundle\Recipient\DoctrineRecipientInterface;
9
10
/**
11
 * Notification Doctrine ORM entity
12
 */
13
class Notification
14
{
15
    /**
16
     * @var int
17
     */
18
    private $id;
19
20
    /**
21
     * @var string
22
     */
23
    private $subject;
24
25
    /**
26
     * @var string
27
     */
28
    private $body;
29
30
    /**
31
     * @var array
32
     */
33
    private $attachments;
34
35
    /**
36
     * @var \DateTime
37
     */
38
    private $recordedAt;
39
40
    /**
41
     * @var string
42
     */
43
    private $recipientClass;
44
45
    /**
46
     * @var int
47
     */
48
    private $recipientId;
49
50
    /**
51
     * @param string                     $subject
52
     * @param string                     $body
53 3
     * @param DoctrineRecipientInterface $recipient
54
     */
55 3
    public function __construct($subject, $body, DoctrineRecipientInterface $recipient)
56 3
    {
57 3
        $this->subject = $subject;
58 3
        $this->body = $body;
59 3
        $this->recipientClass = ClassUtils::getClass($recipient);
60 3
        $this->recipientId = $recipient->getId();
61
        $this->recordedAt = new \DateTime('now');
62
63
        $this->attachments = new ArrayCollection();
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Doctrine\Common\Collections\ArrayCollection() of type object<Doctrine\Common\C...ctions\ArrayCollection> is incompatible with the declared type array of property $attachments.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
64
    }
65 1
66
    /**
67 1
     * @var \DateTime|null
68
     */
69
    private $deliveredAt;
70
71
    /**
72
     * @return integer
73 2
     */
74
    public function getId()
75 2
    {
76
        return $this->id;
77
    }
78
79
    /**
80
     * @return string
81 2
     */
82
    public function getSubject()
83 2
    {
84
        return $this->subject;
85
    }
86
87
    /**
88
     * @return string
89 2
     */
90
    public function getBody()
91 2
    {
92
        return $this->body;
93
    }
94
95
    /**
96
     * @return File[]
97 2
     */
98
    public function getAttachments()
99 2
    {
100
        return $this->attachments;
101
    }
102
103
    /**
104
     * @return string
105 1
     */
106
    public function getRecipientClass()
107 1
    {
108
        return $this->recipientClass;
109
    }
110
111
    /**
112
     * @return int
113 1
     */
114
    public function getRecipientId()
115 1
    {
116
        return $this->recipientId;
117
    }
118
119
    /**
120
     * @return \DateTime
121 2
     */
122
    public function getRecordedAt()
123 2
    {
124
        return $this->recordedAt;
125
    }
126
127
    /**
128 2
     * @return bool
129
     */
130 2
    public function isDelivered()
131 1
    {
132
        return null !== $this->deliveredAt;
133
    }
134 2
135 2
    /**
136
     * @return \DateTime|null
137
     */
138
    public function getDeliveredAt()
139
    {
140
        return $this->deliveredAt;
141
    }
142
143
    /**
144
     */
145
    public function setDelivered()
146
    {
147
        if (null !== $this->deliveredAt) {
148
            return; //immutable
149
        }
150
151
        $this->deliveredAt = new \DateTime('now');
152
    }
153
154
    /**
155
     * @param NotificationAttachment[] $attachments
156
     *
157
     * @return $this
158
     */
159
    public function setAttachments($attachments)
160
    {
161
        $this->attachments = $attachments;
162
    }
163
164
    /**
165
     * @param NotificationAttachment $attachment
166
     */
167
    public function addNotificationAttachment(NotificationAttachment $attachment)
168
    {
169
        $this->attachments->add($attachment);
0 ignored issues
show
Bug introduced by
The method add cannot be called on $this->attachments (of type array).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
170
    }
171
}
172