Failed Conditions
Push — master ( 4252f4...9d8e13 )
by Adrien
07:13
created

Message::setBody()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
ccs 2
cts 2
cp 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Application\Model;
6
7
use Cake\Chronos\Chronos;
8
use Doctrine\ORM\Mapping as ORM;
9
use GraphQL\Doctrine\Annotation as API;
10
11
/**
12
 * A message sent to a user
13
 *
14
 * @ORM\Entity(repositoryClass="Application\Repository\MessageRepository")
15
 */
16
class Message extends AbstractModel
17
{
18
    /**
19
     * @var null|User
20
     *
21
     * @ORM\ManyToOne(targetEntity="User", inversedBy="messages")
22
     */
23
    private $recipient;
24
25
    /**
26
     * @var string
27
     * @ORM\Column(type="string", length=191)
28
     */
29
    private $email;
30
31
    /**
32
     * @var string
33
     *
34
     * @ORM\Column(type="MessageType", length=10)
35
     */
36
    private $type;
37
38
    /**
39
     * @var null|Chronos
40
     *
41
     * @ORM\Column(type="datetime", nullable=true)
42
     */
43
    private $dateSent;
44
45
    /**
46
     * @var string
47
     *
48
     * @ORM\Column(type="string", length=255, options={"default" = ""})
49
     */
50
    private $subject = '';
51
52
    /**
53
     * @var string
54
     *
55
     * @ORM\Column(type="text", length=65535, options={"default" = ""})
56
     */
57
    private $body = '';
58
59
    /**
60
     * Set recipient
61
     *
62
     * @param null|User $recipient
63
     */
64 4
    public function setRecipient(?User $recipient): void
65
    {
66 4
        if ($this->recipient) {
67 1
            $this->recipient->messageRemoved($this);
68
        }
69
70 4
        $this->recipient = $recipient;
71 4
        $this->setOwner($recipient);
72
73 4
        if ($this->recipient) {
74 4
            $this->recipient->messageAdded($this);
75
        }
76 4
    }
77
78
    /**
79
     * Get recipient
80
     *
81
     * @return null|User
82
     */
83 3
    public function getRecipient(): ?User
84
    {
85 3
        return $this->recipient;
86
    }
87
88
    /**
89
     * Set type
90
     *
91
     * @API\Input(type="MessageType")
92
     *
93
     * @param string $type
94
     */
95 3
    public function setType(string $type): void
96
    {
97 3
        $this->type = $type;
98 3
    }
99
100
    /**
101
     * Get type
102
     *
103
     * @API\Field(type="MessageType")
104
     *
105
     * @return string
106
     */
107 1
    public function getType(): string
108
    {
109 1
        return $this->type;
110
    }
111
112
    /**
113
     * @return string
114
     */
115 3
    public function getSubject(): string
116
    {
117 3
        return $this->subject;
118
    }
119
120
    /**
121
     * @param string $subject
122
     */
123 3
    public function setSubject(string $subject): void
124
    {
125 3
        $this->subject = $subject;
126 3
    }
127
128
    /**
129
     * @return string
130
     */
131 2
    public function getBody(): string
132
    {
133 2
        return $this->body;
134
    }
135
136
    /**
137
     * @param string $body
138
     */
139 3
    public function setBody(string $body): void
140
    {
141 3
        $this->body = $body;
142 3
    }
143
144
    /**
145
     * Get sent time
146
     *
147
     * @return null|Chronos
148
     */
149 2
    public function getDateSent(): ?Chronos
150
    {
151 2
        return $this->dateSent;
152
    }
153
154
    /**
155
     * Set sent time
156
     *
157
     * @API\Exclude
158
     *
159
     * @param null|Chronos $dateSent
160
     */
161 1
    public function setDateSent(?Chronos $dateSent): void
162
    {
163 1
        $this->dateSent = $dateSent;
164 1
    }
165
166
    /**
167
     * Recipient email address
168
     *
169
     * @return string
170
     */
171 2
    public function getEmail(): string
172
    {
173 2
        return $this->email;
174
    }
175
176
    /**
177
     * Recipient email address
178
     *
179
     * @param string $email
180
     */
181 4
    public function setEmail(string $email): void
182
    {
183 4
        $this->email = $email;
184 4
    }
185
}
186