Passed
Push — develop ( 2d8f34...faf57e )
by BENARD
29:40 queued 21:31
created

MessageBuilder::setSender()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
namespace ProjetNormandie\MessageBundle\Service;
4
5
use ProjetNormandie\MessageBundle\Entity\Message;
6
use ProjetNormandie\MessageBundle\Repository\MessageRepository;
7
8
/**
9
 * Proxy to send a private message
10
 */
11
class MessageBuilder
12
{
13
    private string $type = 'DEFAULT';
14
    private string $object;
15
    private string $message;
16
    private $sender;
17
    private $recipient;
18
19
    private MessageRepository $messageRepository;
20
21
    /**
22
     * Message constructor.
23
     * @param MessageRepository $messageRepository
24
     */
25
    public function __construct(MessageRepository $messageRepository)
26
    {
27
        $this->messageRepository = $messageRepository;
28
    }
29
30
    /**
31
     * @param string $type
32
     * @return MessageBuilder
33
     */
34
    public function setType(string $type): MessageBuilder
35
    {
36
        $this->type = $type;
37
        return $this;
38
    }
39
40
    /**
41
     * @param string $object
42
     * @return MessageBuilder
43
     */
44
    public function setObject(string $object): MessageBuilder
45
    {
46
        $this->object = $object;
47
        return $this;
48
    }
49
50
    /**
51
     * @param string $message
52
     * @return MessageBuilder
53
     */
54
    public function setMessage(string $message): MessageBuilder
55
    {
56
        $this->message = $message;
57
        return $this;
58
    }
59
    
60
    /**
61
     * @param $sender
62
     * @return MessageBuilder
63
     */
64
    public function setSender($sender): MessageBuilder
65
    {
66
        $this->sender = $sender;
67
        return $this;
68
    }
69
    
70
    /**
71
     * @param $recipient
72
     * @return MessageBuilder
73
     */
74
    public function setRecipient($recipient): MessageBuilder
75
    {
76
        $this->recipient = $recipient;
77
        return $this;
78
    }
79
80
    public function send()
81
    {
82
        $message = new Message();
83
        $message
84
            ->setType($this->type)
85
            ->setObject($this->object)
86
            ->setMessage($this->message)
87
            ->setSender($this->sender)
88
            ->setRecipient($this->recipient)
89
            ->setIsDeletedSender(true)
90
            ;
91
92
        $this->messageRepository->save($message);
93
    }
94
}
95