Completed
Push — develop ( e210c1...b7d5d2 )
by Mohamed
07:16 queued 59s
created

QueueTrait::queueAdd()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 9
Ratio 100 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 9
loc 9
ccs 4
cts 4
cp 1
rs 9.6666
cc 2
eloc 4
nc 2
nop 1
crap 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\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)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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());
0 ignored issues
show
Documentation introduced by
auth()->user() is of type object<Illuminate\Contra...h\Authenticatable>|null, but the function expects a object<Tinyissue\Model\User>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
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)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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());
0 ignored issues
show
Documentation introduced by
auth()->user() is of type object<Illuminate\Contra...h\Authenticatable>|null, but the function expects a object<Tinyissue\Model\User>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
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)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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());
0 ignored issues
show
Documentation introduced by
auth()->user() is of type object<Illuminate\Contra...h\Authenticatable>|null, but the function expects a object<Tinyissue\Model\User>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
74
    }
75
}
76