NewMessageManager::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 2
1
<?php
2
3
/*
4
 * This file is part of the MilioooMessageBundle package.
5
 *
6
 * (c) Michiel boeckaert <[email protected]>
7
 * This source file is subject to the MIT license that is bundled
8
 * with this source code in the file LICENSE.
9
 */
10
11
namespace Miliooo\Messaging\Manager;
12
13
use Miliooo\Messaging\Repository\MessageRepositoryInterface;
14
use Miliooo\Messaging\Repository\ThreadRepositoryInterface;
15
use Miliooo\Messaging\Model\MessageInterface;
16
17
/**
18
 * The new message manager is responsible for saving new messages
19
 *
20
 * @author Michiel Boeckaert <[email protected]>
21
 */
22
class NewMessageManager implements NewMessageManagerInterface
23
{
24
    /**
25
     * A message repository instance.
26
     *
27
     * @var MessageRepositoryInterface
28
     */
29
    protected $messageRepository;
30
31
    /**
32
     * A thread repository instance.
33
     *
34
     * @var ThreadRepositoryInterface
35
     */
36
    protected $threadRepository;
37
38
    /**
39
     * Constructor.
40
     *
41
     * @param MessageRepositoryInterface $messageRepository
42
     * @param ThreadRepositoryInterface $threadRepository
43
     */
44
    public function __construct(
45
        MessageRepositoryInterface $messageRepository,
46
        ThreadRepositoryInterface $threadRepository
47
    ) {
48
        $this->messageRepository = $messageRepository;
49
        $this->threadRepository = $threadRepository;
50
    }
51
52
    /**
53
     * {@inheritdoc}
54
     */
55
    public function saveNewThread(MessageInterface $message)
56
    {
57
        $this->saveNewMessage($message);
58
    }
59
60
    /**
61
     * {@inheritdoc}
62
     */
63
    public function saveNewReply(MessageInterface $message)
64
    {
65
        $this->saveNewMessage($message);
66
    }
67
68
    /**
69
     * Saves a new message to the persistent storage
70
     *
71
     * @param MessageInterface $message
72
     */
73
    protected function saveNewMessage(MessageInterface $message)
74
    {
75
        $thread = $message->getThread();
76
        $this->messageRepository->save($message, false);
77
        $this->threadRepository->save($thread, true);
78
    }
79
}
80