Completed
Push — master ( 127008...59a424 )
by Charles
04:01
created

Queue   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
lcom 1
cbo 5
dl 0
loc 43
rs 10
c 1
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setClients() 0 8 2
A get() 0 4 1
A addJob() 0 5 1
1
<?php
2
3
namespace yrc\components;
4
5
use Yii;
6
use yii\base\Object;
7
use Disque\Connection\Credentials;
8
use Disque\Client;
9
10
/**
11
 * Disque Manager
12
 * @class Queue
13
 */
14
class Queue extends Object
15
{
16
    /**
17
     * An array of Disque connections
18
     * @param array $nodes
19
     */
20
    private $nodes;
21
22
    /**
23
     * Adds client connections
24
     * @param array $clients
25
     * @return true
26
     */
27
    public function setClients($clients = [])
28
    {
29
        foreach ($clients as $client) {
30
            $this->nodes[] = new Credentials($client['host'], $client['port'], $client['password']);
31
        }
32
33
        return true;
34
    }
35
36
    /**
37
     * Retrieves the queue
38
     * @return Disque\Client
39
     */
40
    public function get()
41
    {
42
        return new Client($this->nodes);
0 ignored issues
show
Documentation introduced by
$this->nodes is of type array<integer,object<Dis...onnection\Credentials>>, but the function expects a array<integer,object<Dis...onnection\Credentials>>.

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
    /**
46
     * Adds a new job to a queue
47
     * @param array $jobProperties
48
     * @param string $queueName
49
     * return
50
     */
51
    public function addJob($jobProperties = [], $queueName = 'app')
52
    {
53
        $job = new \Disque\Queue\Job($jobProperties);
54
        return $this->get()->queue($queueName)->push($job);
55
    }
56
}