Completed
Push — develop ( 64265e...12ceca )
by Mohamed
10:07
created

QueueTrait::queueUpdate()   C

Complexity

Conditions 7
Paths 6

Size

Total Lines 31
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 31
rs 6.7272
cc 7
eloc 13
nc 6
nop 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;
16
use Tinyissue\Model\User;
17
use Tinyissue\Model\Message\Queue;
18
19
/**
20
 * QueueTrait is trait class for adding method to insert records into a queue.
21
 *
22
 * @author Mohamed Alsharaf <[email protected]>
23
 */
24
trait QueueTrait
25
{
26
    /**
27
     * Insert update issue to message queue.
28
     *
29
     * @param Issue $issue
30
     *
31
     * @return void
32
     */
33
    public function queueUpdate(Issue $issue)
34
    {
35
        // Number of changed attributes
36
        $countChanges = count($issue->getDirty());
37
38
        // Whether or not the assignee has changed
39
        $noMessageForMe = false;
40
41
        // is Closed?
42
        if (!$issue->isOpen()) {
43
            return (new Message\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...
44
        }
45
46
        // is Reopened?
47
        if ((int) $issue->getOriginal('status') === Issue::STATUS_CLOSED) {
48
            return (new Message\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...
49
        }
50
51
        // If the assignee has changed and it is not the logged in user who made the action
52
        if ($issue->assigned_to !== $issue->getOriginal('assigned_to', $issue->assigned_to)
53
            && 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...
54
        ) {
55
            (new Message\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...
56
            $noMessageForMe = $issue->assigned_to;
57
        }
58
59
        // If the update was just for assigning user, then skip update issue
60
        if (!($countChanges === 1 && $noMessageForMe !== false)) {
61
            return (new Message\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...
62
        }
63
    }
64
65
    /**
66
     * Insert add issue to message queue.
67
     *
68
     * @param Issue $issue
69
     *
70
     * @return void
71
     */
72
    public function queueAdd(Issue $issue)
73
    {
74
        return (new Message\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...
75
    }
76
77
    /**
78
     * Insert assign issue to message queue.
79
     *
80
     * @param Issue $issue
81
     *
82
     * @return void
83
     */
84
    public function queueAssign(Issue $issue)
85
    {
86
        // If the assignee has changed and it is not the logged in user who made the action
87
        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...
88
            return (new Message\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...
89
        }
90
    }
91
92
    /**
93
     * Insert issue tag changes to message queue.
94
     *
95
     * @param Issue $issue
96
     * @param array $addedTags
97
     * @param array $removedTags
98
     *
99
     * @return mixed
100
     */
101
    public function queueChangeTags(Issue $issue, array $addedTags, array $removedTags)
102
    {
103
        $user  = auth()->user();
104
        $queue = new Message\Queue();
105
106
        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...
107
    }
108
}
109