Passed
Push — master ( 0398fd...04e2c5 )
by Ashley
01:52
created

Queue   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Test Coverage

Coverage 28.57%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 57
ccs 4
cts 14
cp 0.2857
rs 10
c 1
b 0
f 0
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A push() 0 2 1
A worker() 0 2 1
A cron() 0 5 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 string
16
	 */
17
	protected $identifier;
18
19
	/**
20
	 * Queue constructor.
21
	 *
22
	 * @param ConnectionInterface $connection
23
	 * @param string              $identifier
24
	 */
25 1
	public function __construct( ConnectionInterface $connection, $identifier ) {
26 1
		$this->connection = $connection;
27 1
		$this->identifier = $identifier;
28 1
	}
29
30
	/**
31
	 * Push a job onto the queue;
32
	 *
33
	 * @param Job $job
34
	 * @param int $delay
35
	 *
36
	 * @return bool|int
37
	 */
38
	public function push( Job $job, $delay = 0 ) {
39
		return $this->connection->push( $job, $delay );
40
	}
41
42
	/**
43
	 * Create a cron worker.
44
	 *
45
	 * @param int $attempts
46
	 */
47
	public function cron( $attempts = 3 ) {
48
		$cron = new Cron( $this->identifier, $this->worker( $attempts ) );
49
50
		if ( $cron->is_enabled() ) {
51
			$cron->init();
52
		}
53
	}
54
55
	/**
56
	 * Create a new worker.
57
	 *
58
	 * @param int $attempts
59
	 *
60
	 * @return Worker
61
	 */
62
	public function worker( $attempts ) {
63
		return new Worker( $this->connection, $attempts );
64
	}
65
}