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

MessageBuilder   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 27
c 1
b 0
f 0
dl 0
loc 82
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A send() 0 13 1
A setType() 0 4 1
A setSender() 0 4 1
A setObject() 0 4 1
A setRecipient() 0 4 1
A setMessage() 0 4 1
A __construct() 0 3 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