JobQueue::all()   A
last analyzed

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 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
namespace tomzx\Job;
4
5
class JobQueue
6
{
7
    /**
8
     * @var Job[]
9
     */
10
    private $queue = [];
11
12
    /**
13
     * @param \tomzx\Job\Job $job
14
     */
15 16
    public function push(Job $job)
16
    {
17 16
        $this->queue[] = $job;
18 16
    }
19
20
    /**
21
     * @return mixed|\tomzx\Job\Job
22
     */
23 7
    public function pop()
24
    {
25 7
        return array_shift($this->queue);
26
    }
27
28
    /**
29
     * @return \tomzx\Job\Job[]
30
     */
31 13
    public function all()
32
    {
33 13
        return $this->queue;
34
    }
35
36
    /**
37
     * @return bool
38
     */
39 12
    public function isEmpty()
40
    {
41 12
        return empty($this->queue);
42
    }
43
44
    /**
45
     * @return int
46
     */
47 10
    public function count()
48
    {
49 10
        return count($this->queue);
50
    }
51
52
    /**
53
     * @param \tomzx\Job\Job $job
54
     */
55 7
    public function remove(Job $job)
56
    {
57 7
        $index = array_search($job, $this->queue);
58 7
        if ($index !== false) {
59 6
            unset($this->queue[$index]);
60
        }
61 7
    }
62
}
63