Completed
Push — master ( 195b94...7a36f1 )
by Mohamed
04:50
created

QueueTrait::queueDelete()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 9
rs 9.6666
c 1
b 0
f 0
cc 3
eloc 4
nc 2
nop 2
1
<?php
2
3
/*
4
 * This file is part of the Tinyissue package.
5
 *
6
 * (c) Mohamed Alsharaf <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Tinyissue\Model\Traits\Project\Issue\Comment;
13
14
use Tinyissue\Model\Project\Issue\Comment;
15
use Tinyissue\Model\Project\Issue;
16
use Tinyissue\Model\Message;
17
use Tinyissue\Model\Message\Queue;
18
use Tinyissue\Model\User;
19
20
/**
21
 * QueueTrait is trait class for adding method to insert records into a queue.
22
 *
23
 * @author Mohamed Alsharaf <[email protected]>
24
 *
25
 * @property static $this
26
 */
27
trait QueueTrait
28
{
29
    /**
30
     * Insert add comment to message queue.
31
     *
32
     * @param Comment  $comment
33
     * @param int|User $changeBy
34
     *
35
     * @return void
36
     */
37
    public function queueAdd(Comment $comment, $changeBy)
38
    {
39
        // Skip message if issue closed
40
        if (!$comment->issue->isOpen()) {
41
            return;
42
        }
43
44
        return (new Message\Queue())->queue(Queue::ADD_COMMENT, $comment, $changeBy);
45
    }
46
47
    /**
48
     * Insert update comment to message queue.
49
     *
50
     * @param Comment  $comment
51
     * @param int|User $changeBy
52
     *
53
     * @return void
54
     */
55
    public function queueUpdate(Comment $comment, $changeBy)
56
    {
57
        // Skip message if issue closed or nothing changed in comment
58
        if (!$comment->issue->isOpen() || !$comment->isDirty()) {
59
            return;
60
        }
61
62
        return (new Message\Queue())->queue(Queue::UPDATE_COMMENT, $comment, $changeBy);
63
    }
64
65
    /**
66
     * Insert delete comment to message queue.
67
     *
68
     * @param Comment  $comment
69
     * @param int|User $changeBy
70
     *
71
     * @return void
72
     */
73
    public function queueDelete(Comment $comment, $changeBy)
74
    {
75
        // Skip message if issue closed
76
        if ($comment->issue instanceof Issue && !$comment->issue->isOpen()) {
77
            return;
78
        }
79
80
        return (new Message\Queue())->queueDelete(Queue::DELETE_COMMENT, $comment, $changeBy);
81
    }
82
}
83