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\Message; |
16
|
|
|
use Tinyissue\Model\Message\Queue; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* QueueTrait is trait class for adding method to insert records into a queue. |
20
|
|
|
* |
21
|
|
|
* @author Mohamed Alsharaf <[email protected]> |
22
|
|
|
*/ |
23
|
|
|
trait QueueTrait |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* Insert add comment to message queue. |
27
|
|
|
* |
28
|
|
|
* @param Comment $comment |
29
|
|
|
* |
30
|
|
|
* @return void |
31
|
|
|
*/ |
32
|
6 |
View Code Duplication |
public function queueAdd(Comment $comment) |
|
|
|
|
33
|
|
|
{ |
34
|
|
|
// Skip message if issue closed |
35
|
6 |
|
if (!$comment->issue->isOpen()) { |
36
|
3 |
|
return; |
37
|
|
|
} |
38
|
|
|
|
39
|
3 |
|
return (new Message\Queue())->queue(Queue::ADD_COMMENT, $comment, auth()->user()); |
|
|
|
|
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Insert update comment to message queue. |
44
|
|
|
* |
45
|
|
|
* @param Comment $comment |
46
|
|
|
* |
47
|
|
|
* @return void |
48
|
|
|
*/ |
49
|
1 |
View Code Duplication |
public function queueUpdate(Comment $comment) |
|
|
|
|
50
|
|
|
{ |
51
|
|
|
// Skip message if issue closed or nothing changed in comment |
52
|
1 |
|
if (!$comment->issue->isOpen() || !$comment->isDirty()) { |
53
|
|
|
return; |
54
|
|
|
} |
55
|
|
|
|
56
|
1 |
|
return (new Message\Queue())->queue(Queue::UPDATE_COMMENT, $comment, auth()->user()); |
|
|
|
|
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Insert delete comment to message queue. |
61
|
|
|
* |
62
|
|
|
* @param Comment $comment |
63
|
|
|
* |
64
|
|
|
* @return void |
65
|
|
|
*/ |
66
|
1 |
View Code Duplication |
public function queueDelete(Comment $comment) |
|
|
|
|
67
|
|
|
{ |
68
|
|
|
// Skip message if issue closed |
69
|
1 |
|
if (!$comment->issue->isOpen()) { |
70
|
|
|
return; |
71
|
|
|
} |
72
|
|
|
|
73
|
1 |
|
return (new Message\Queue())->queueDelete(Queue::DELETE_COMMENT, $comment, auth()->user()); |
|
|
|
|
74
|
|
|
} |
75
|
|
|
} |
76
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.