Completed
Branch develop-3.0 (63d375)
by Mohamed
02:58
created

MessageQueuer   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 8
c 0
b 0
f 0
lcom 0
cbo 4
dl 0
loc 56
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A queueAdd() 0 9 2
A queueUpdate() 0 9 3
A queueDelete() 0 9 3
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\Repository\Project\Issue\Comment;
13
14
use Tinyissue\Model;
15
use Tinyissue\Model\Message\Queue;
16
use Tinyissue\Model\Project\Issue\Comment as CommentModel;
17
18
trait MessageQueuer
19
{
20
    /**
21
     * Insert add comment to message queue.
22
     *
23
     * @param CommentModel $comment
24
     * @param Model\User   $changeBy
25
     *
26
     * @return void
27
     */
28
    public function queueAdd(CommentModel $comment, Model\User $changeBy)
29
    {
30
        // Skip message if issue closed
31
        if (!$comment->issue->isOpen()) {
32
            return;
33
        }
34
35
        return (new Queue())->updater($changeBy)->queue(Queue::ADD_COMMENT, $comment, $changeBy);
36
    }
37
38
    /**
39
     * Insert update comment to message queue.
40
     *
41
     * @param CommentModel $comment
42
     * @param Model\User   $changeBy
43
     *
44
     * @return void
45
     */
46
    public function queueUpdate(CommentModel $comment, Model\User $changeBy)
47
    {
48
        // Skip message if issue closed or nothing changed in comment
49
        if (!$comment->issue->isOpen() || !$comment->isDirty()) {
50
            return;
51
        }
52
53
        return (new Queue())->updater($changeBy)->queue(Queue::UPDATE_COMMENT, $comment, $changeBy);
54
    }
55
56
    /**
57
     * Insert delete comment to message queue.
58
     *
59
     * @param CommentModel $comment
60
     * @param Model\User   $changeBy
61
     *
62
     * @return void
63
     */
64
    public function queueDelete(CommentModel $comment, Model\User $changeBy)
65
    {
66
        // Skip message if issue closed
67
        if ($comment->issue instanceof Issue && !$comment->issue->isOpen()) {
0 ignored issues
show
Bug introduced by
The class Tinyissue\Repository\Project\Issue\Comment\Issue does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
68
            return;
69
        }
70
71
        return (new Queue())->updater($changeBy)->queueDelete(Queue::DELETE_COMMENT, $comment, $changeBy);
72
    }
73
}
74