Completed
Push — master ( 4109b7...859c70 )
by Matthew
08:07 queued 02:26
created

Worker   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 96
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 90%

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 0
dl 0
loc 96
ccs 27
cts 30
cp 0.9
rs 10
c 0
b 0
f 0

10 Methods

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