Queue   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 59
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A push() 0 2 1
A worker() 0 2 1
A cron() 0 7 2
1
<?php
2
3
namespace WP_Queue;
4
5
use WP_Queue\Connections\ConnectionInterface;
6
7
class Queue {
8
9
	/**
10
	 * @var ConnectionInterface
11
	 */
12
	protected $connection;
13
14
	/**
15
	 * @var Cron
16
	 */
17
	protected $cron;
18
19
	/**
20
	 * Queue constructor.
21
	 *
22
	 * @param ConnectionInterface $connection
23
	 */
24 5
	public function __construct( ConnectionInterface $connection ) {
25 5
		$this->connection = $connection;
26 5
	}
27
28
	/**
29
	 * Push a job onto the queue;
30
	 *
31
	 * @param Job $job
32
	 * @param int $delay
33
	 *
34
	 * @return bool|int
35
	 */
36 2
	public function push( Job $job, $delay = 0 ) {
37 2
		return $this->connection->push( $job, $delay );
38
	}
39
40
	/**
41
	 * Create a cron worker.
42
	 *
43
	 * @param int $attempts
44
	 * @param int $interval
45
	 *
46
	 * @return Cron
47
	 */
48 1
	public function cron( $attempts = 3, $interval = 5 ) {
49 1
		if ( is_null( $this->cron ) ) {
50 1
			$this->cron	= new Cron( get_class( $this->connection ), $this->worker( $attempts ), $interval );
51 1
			$this->cron->init();
52
		}
53
54 1
		return $this->cron;
55
	}
56
57
	/**
58
	 * Create a new worker.
59
	 *
60
	 * @param int $attempts
61
	 *
62
	 * @return Worker
63
	 */
64 2
	public function worker( $attempts ) {
65 2
		return new Worker( $this->connection, $attempts );
66
	}
67
}