NewMessageManager   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 58
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A saveNewThread() 0 4 1
A saveNewReply() 0 4 1
A saveNewMessage() 0 6 1
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