Queue::getJobs()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 12
rs 9.4285
cc 2
eloc 7
nc 2
nop 2
1
<?php
2
3
namespace Mpclarkson\ResqueBundle;
4
5
/**
6
 * Class Queue
7
 * @package Mpclarkson\ResqueBundle
8
 */
9
class Queue
10
{
11
    /**
12
     * @var string The queue name
13
     */
14
    private $name;
15
16
    public function __construct($name)
17
    {
18
        $this->name = $name;
19
    }
20
21
    /**
22
     * @return int
23
     */
24
    public function getSize()
25
    {
26
        return \Resque::size($this->name);
27
    }
28
29
    /**
30
     * @return string
31
     */
32
    public function getName()
33
    {
34
        return $this->name;
35
    }
36
37
    /**
38
     * @param int $start
39
     * @param int $stop
40
     * @return array
41
     */
42
    public function getJobs($start = 0, $stop = -1)
43
    {
44
        $jobs = \Resque::redis()->lrange('queue:' . $this->name, $start, $stop);
45
46
        $result = [];
47
        foreach ($jobs as $job) {
48
            $job = new \Resque_Job($this->name, \json_decode($job, TRUE));
49
            $result[] = $job->getInstance();
50
        }
51
52
        return $result;
53
    }
54
}
55