Passed
Push — master ( 8116cf...9d59f1 )
by Adrien
06:29
created

Message::getRecipient()   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 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
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 User
20
     *
21
     * @ORM\ManyToOne(targetEntity="User", inversedBy="messages")
22
     * @ORM\JoinColumns({
23
     *     @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
24
     * })
25
     */
26
    private $recipient;
27
28
    /**
29
     * @var string
30
     *
31
     * @ORM\Column(type="MessageType", length=10)
32
     */
33
    private $type;
34
35
    /**
36
     * @var Chronos
37
     *
38
     * @ORM\Column(type="datetime", nullable=true)
39
     */
40
    private $dateSent;
41
42
    /**
43
     * @var string
44
     *
45
     * @ORM\Column(type="string", length=255, options={"default" = ""})
46
     */
47
    private $subject = '';
48
49
    /**
50
     * @var string
51
     *
52
     * @ORM\Column(type="text", length=65535, options={"default" = ""})
53
     */
54
    private $body = '';
55
56
    /**
57
     * Set recipient
58
     *
59
     * @param User $recipient
60
     */
61 1
    public function setRecipient(User $recipient): void
62
    {
63 1
        if ($this->recipient && $this->recipient !== $recipient) {
64 1
            $this->recipient->messageRemoved($this);
65
        }
66
67 1
        $this->recipient = $recipient;
68 1
        $this->setOwner($recipient);
69 1
        $recipient->messageAdded($this);
70 1
    }
71
72
    /**
73
     * Get recipient
74
     *
75
     * @return User
76
     */
77 1
    public function getRecipient(): User
78
    {
79 1
        return $this->recipient;
80
    }
81
82
    /**
83
     * Set type
84
     *
85
     * @API\Input(type="MessageType")
86
     *
87
     * @param string $type
88
     */
89
    public function setType(string $type): void
90
    {
91
        $this->type = $type;
92
    }
93
94
    /**
95
     * Get type
96
     *
97
     * @API\Field(type="MessageType")
98
     *
99
     * @return string
100
     */
101
    public function getType(): string
102
    {
103
        return $this->type;
104
    }
105
106
    /**
107
     * @return string
108
     */
109 1
    public function getSubject(): string
110
    {
111 1
        return $this->subject;
112
    }
113
114
    /**
115
     * @param string $subject
116
     */
117
    public function setSubject(string $subject): void
118
    {
119
        $this->subject = $subject;
120
    }
121
122
    /**
123
     * @return string
124
     */
125
    public function getBody(): string
126
    {
127
        return $this->body;
128
    }
129
130
    /**
131
     * @param string $body
132
     */
133
    public function setBody(string $body): void
134
    {
135
        $this->body = $body;
136
    }
137
138
    /**
139
     * Get sent time
140
     *
141
     * @return null|Chronos
142
     */
143
    public function getDateSent(): ?Chronos
144
    {
145
        return $this->dateSent;
146
    }
147
148
    /**
149
     * Set sent time
150
     *
151
     * @param null|Chronos $dateSent
152
     */
153
    public function setDateSent(?Chronos $dateSent): void
154
    {
155
        $this->dateSent = $dateSent;
156
    }
157
}
158