Queue   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 0 Features 3
Metric Value
wmc 5
c 4
b 0
f 3
lcom 2
cbo 2
dl 0
loc 75
ccs 15
cts 15
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A len() 0 4 1
A peek() 0 4 1
A scan() 0 10 1
A enqueue() 0 4 1
A dequeue() 0 4 1
1
<?php
2
3
namespace Phloppy\Client;
4
5
use Iterator;
6
use Phloppy\Client\Queue\QScanIterator;
7
use Phloppy\Job;
8
9
/**
10
 * Queue introspection commands.
11
 */
12
class Queue extends AbstractClient {
13
14
    /**
15
     * Returns the length of the queue.
16
     *
17
     * @param $queue
18
     * @return int
19
     */
20 4
    public function len($queue)
21
    {
22 4
        return (int) $this->send(['QLEN', $queue]);
23
    }
24
25
26
    /**
27
     * Peek count jobs from the given queue without removing them.
28
     *
29
     * @param string $queue
30
     * @param int $count
31
     *
32
     * @return Job[]
33
     */
34 1
    public function peek($queue, $count = 1)
35
    {
36 1
        return $this->mapJobs($this->send(['QPEEK', $queue, $count]));
37
    }
38
39
40
    /**
41
     * Scan all existing queues.
42
     *
43
     * Options may be used to filter the scan results.
44
     *
45
     * @param int $count Return count elements per call. A count of 0 implies returning all elements at once.
46
     * @param int $min Filter queues with at least min elements.
47
     * @param int $max Filter queues with at most max elements.
48
     * @param int $rate Filter queues by job import rate.
49
     *
50
     * @return Iterator
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use QScanIterator.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
51
     */
52 2
    public function scan($count = 50, $min = 0, $max = 0, $rate = 0)
53
    {
54 2
        $iterator = new QScanIterator($this->stream, $this->log);
55 2
        $iterator->setCount($count)
56 2
            ->setMin($min)
57 2
            ->setMax($max)
58 2
            ->setRate($rate);
59
60 2
        return $iterator;
61
    }
62
63
64
    /**
65
     * Enqueue the given job Ids.
66
     *
67
     * @param string[] $jobIds
68
     * @return int
69
     */
70 1
    public function enqueue(array $jobIds)
71
    {
72 1
        return (int) $this->send(array_merge(['ENQUEUE'], $jobIds));
73
    }
74
75
76
    /**
77
     * Dequeue the given job Ids.
78
     *
79
     * @param string[] $jobIds
80
     * @return int
81
     */
82 1
    public function dequeue(array $jobIds)
83
    {
84 1
        return (int) $this->send(array_merge(['DEQUEUE'], $jobIds));
85
    }
86
}
87