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

QueueTrait::queueAdd()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
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;
13
14
use Tinyissue\Model\Project\Issue;
15
use Tinyissue\Model\Message\Queue;
16
use Tinyissue\Model\User;
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 update issue to message queue.
27
     *
28
     * @param Issue $issue
29
     *
30
     * @return void
31
     */
32 5
    public function queueUpdate(Issue $issue)
33
    {
34
        // Number of changed attributes
35 5
        $countChanges = count($issue->getDirty());
36
37
        // Whether or not the assignee has changed
38 5
        $noMessageForMe = false;
39
40
        // is Closed?
41 5
        if (!$issue->isOpen()) {
42 4
            return (new Queue())->queue(Queue::CLOSE_ISSUE, $issue, 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...
43
        }
44
45
        // is Reopened?
46 2
        if ((int) $issue->getOriginal('status') === Issue::STATUS_CLOSED) {
47 1
            return (new Queue())->queue(Queue::REOPEN_ISSUE, $issue, 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...
48
        }
49
50
        // If the assignee has changed and it is not the logged in user who made the action
51 1
        if ($issue->assigned_to !== $issue->getOriginal('assigned_to', $issue->assigned_to)
52 1
            && auth()->user()->id !== $issue->assigned_to
0 ignored issues
show
Bug introduced by
Accessing id on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
53
        ) {
54
            (new Queue())->queue(Queue::ASSIGN_ISSUE, $issue, 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...
55
            $noMessageForMe = $issue->assigned_to;
56
        }
57
58
        // If the update was just for assigning user, then skip update issue
59 1
        if (!($countChanges === 1 && $noMessageForMe !== false)) {
60 1
            return (new Queue())->queue(Queue::UPDATE_ISSUE, $issue, 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...
61
        }
62
    }
63
64
    /**
65
     * Insert add issue to message queue.
66
     *
67
     * @param Issue $issue
68
     *
69
     * @return void
70
     */
71 28
    public function queueAdd(Issue $issue)
72
    {
73 28
        return (new Queue())->queue(Queue::ADD_ISSUE, $issue, 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
    /**
77
     * Insert assign issue to message queue.
78
     *
79
     * @param Issue $issue
80
     *
81
     * @return void
82
     */
83 2
    public function queueAssign(Issue $issue)
84
    {
85
        // If the assignee has changed and it is not the logged in user who made the action
86 2
        if ($issue->assigned_to > 0 && auth()->user()->id !== $issue->assigned_to) {
0 ignored issues
show
Bug introduced by
Accessing id on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
87 2
            return (new Queue())->queue(Queue::ASSIGN_ISSUE, $issue, 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...
88
        }
89
    }
90
91
    /**
92
     * Insert issue tag changes to message queue.
93
     *
94
     * @param Issue $issue
95
     * @param array $addedTags
96
     * @param array $removedTags
97
     *
98
     * @return mixed
99
     */
100 2
    public function queueChangeTags(Issue $issue, array $addedTags, array $removedTags)
101
    {
102 2
        $user  = auth()->user();
103 2
        $queue = new Queue();
104
105 2
        return $queue->queueIssueTagChanges($issue, $addedTags, $removedTags, $user);
0 ignored issues
show
Documentation introduced by
$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...
106
    }
107
}
108