Completed
Push — master ( 2db41f...aa6ae6 )
by Matthew
15:06 queued 36s
created

Worker::getJobManager()   A

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 Dtc\QueueBundle\Model;
4
5
abstract class Worker
6
{
7
    protected $jobManager;
8
    protected $jobClass;
9
    protected $job;
10
11
    /**
12
     * @return string
13
     */
14 13
    public function getJobClass()
15
    {
16 13
        return $this->jobClass;
17
    }
18
19
    /**
20
     * @param string $jobClass
21
     */
22 12
    public function setJobClass($jobClass)
23
    {
24 12
        $this->jobClass = $jobClass;
25 12
    }
26
27
    /**
28
     * @param JobManagerInterface $jobManager
29
     */
30 22
    public function setJobManager(JobManagerInterface $jobManager)
31
    {
32 22
        $this->jobManager = $jobManager;
33 22
    }
34
35
    /**
36
     * @return
37
     */
38 61
    public function getJobManager()
39
    {
40 61
        return $this->jobManager;
41
    }
42
43
    /**
44
     * @param int|null $time
45
     * @param bool     $batch
46
     * @param int|null $priority
47
     */
48 18
    public function at($time = null, $batch = false, $priority = null)
49
    {
50 18
        if (null === $time) {
51
            $time = time();
52
        }
53 18
        $dateTime = new \DateTime("@$time");
54
55 18
        return new $this->jobClass($this, $batch, $priority, $dateTime);
56
    }
57
58
    /**
59
     * @param int      $delay    Amount of time to delay
60
     * @param int|null $priority
61
     */
62 15
    public function later($delay = 0, $priority = null)
63
    {
64 15
        return $this->batchOrLaterDelay($delay, false, $priority);
65
    }
66
67 16
    public function batchOrLaterDelay($delay = 0, $batch = false, $priority = null)
68
    {
69 16
        $job = $this->at(time() + $delay, $batch, $priority);
70 16
        $job->setDelay($delay);
71
72 16
        return $job;
73
    }
74
75
    /**
76
     * @param int      $delay    Amount of time to delay
77
     * @param int|null $priority
78
     */
79 3
    public function batchLater($delay = 0, $priority = null)
80
    {
81 3
        return $this->batchOrLaterDelay($delay, true, $priority);
82
    }
83
84
    /**
85
     * @param int|null $time
86
     * @param int|null $priority
87
     */
88 1
    public function batchAt($time = null, $priority = null)
89
    {
90 1
        return $this->at($time, true, $priority);
91
    }
92
93
    abstract public function getName();
94
}
95