Completed
Pull Request — master (#5)
by Ian
04:04
created
src/WP_Queue/Connections/DatabaseConnection.php 1 patch
Spacing   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
 	 *
29 29
 	 * @param \wpdb $wpdb
30 30
 	 */
31
-	public function __construct( $wpdb ) {
31
+	public function __construct($wpdb) {
32 32
 		$this->database       = $wpdb;
33 33
 		$this->jobs_table     = $this->database->prefix . 'queue_jobs';
34 34
 		$this->failures_table = $this->database->prefix . 'queue_failures';
@@ -42,14 +42,14 @@  discard block
 block discarded – undo
42 42
 	 *
43 43
 	 * @return bool|int
44 44
 	 */
45
-	public function push( Job $job, $delay = 0 ) {
46
-		$result = $this->database->insert( $this->jobs_table, array(
47
-			'job'          => serialize( $job ),
48
-			'available_at' => $this->datetime( $delay ),
45
+	public function push(Job $job, $delay = 0) {
46
+		$result = $this->database->insert($this->jobs_table, array(
47
+			'job'          => serialize($job),
48
+			'available_at' => $this->datetime($delay),
49 49
 			'created_at'   => $this->datetime(),
50
-		) );
50
+		));
51 51
 
52
-		if ( ! $result ) {
52
+		if ( ! $result) {
53 53
 			return false;
54 54
 		}
55 55
 
@@ -64,23 +64,23 @@  discard block
 block discarded – undo
64 64
 	public function pop() {
65 65
 		$this->release_reserved();
66 66
 
67
-		$sql = $this->database->prepare( "
67
+		$sql = $this->database->prepare("
68 68
 			SELECT * FROM {$this->jobs_table}
69 69
 			WHERE reserved_at IS NULL
70 70
 			AND available_at <= %s
71 71
 			ORDER BY available_at
72 72
 			LIMIT 1
73
-		", $this->datetime() );
73
+		", $this->datetime());
74 74
 
75
-		$raw_job = $this->database->get_row( $sql );
75
+		$raw_job = $this->database->get_row($sql);
76 76
 
77
-		if ( is_null( $raw_job ) ) {
77
+		if (is_null($raw_job)) {
78 78
 			return false;
79 79
 		}
80 80
 
81
-		$job = $this->vitalize_job( $raw_job );
81
+		$job = $this->vitalize_job($raw_job);
82 82
 
83
-		$this->reserve( $job );
83
+		$this->reserve($job);
84 84
 
85 85
 		return $job;
86 86
 	}
@@ -92,12 +92,12 @@  discard block
 block discarded – undo
92 92
 	 *
93 93
 	 * @return bool
94 94
 	 */
95
-	public function delete( $job ) {
95
+	public function delete($job) {
96 96
 		$where = array(
97 97
 			'id' => $job->id(),
98 98
 		);
99 99
 
100
-		if ( $this->database->delete( $this->jobs_table, $where ) ) {
100
+		if ($this->database->delete($this->jobs_table, $where)) {
101 101
 			return true;
102 102
 		}
103 103
 
@@ -111,9 +111,9 @@  discard block
 block discarded – undo
111 111
 	 *
112 112
 	 * @return bool
113 113
 	 */
114
-	public function release( $job ) {
115
-		$data  = array(
116
-			'job'         => serialize( $job ),
114
+	public function release($job) {
115
+		$data = array(
116
+			'job'         => serialize($job),
117 117
 			'attempts'    => $job->attempts(),
118 118
 			'reserved_at' => null,
119 119
 		);
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
 			'id' => $job->id(),
122 122
 		);
123 123
 
124
-		if ( $this->database->update( $this->jobs_table, $data, $where ) ) {
124
+		if ($this->database->update($this->jobs_table, $data, $where)) {
125 125
 			return true;
126 126
 		}
127 127
 
@@ -136,15 +136,15 @@  discard block
 block discarded – undo
136 136
 	 *
137 137
 	 * @return bool
138 138
 	 */
139
-	public function failure( $job, Exception $exception ) {
140
-		$insert = $this->database->insert( $this->failures_table, array(
141
-			'job'       => serialize( $job ),
142
-			'error'     => $this->format_exception( $exception ),
139
+	public function failure($job, Exception $exception) {
140
+		$insert = $this->database->insert($this->failures_table, array(
141
+			'job'       => serialize($job),
142
+			'error'     => $this->format_exception($exception),
143 143
 			'failed_at' => $this->datetime(),
144
-		) );
144
+		));
145 145
 
146
-		if ( $insert ) {
147
-			$this->delete( $job );
146
+		if ($insert) {
147
+			$this->delete($job);
148 148
 
149 149
 			return true;
150 150
 		}
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
 	public function jobs() {
161 161
 		$sql = "SELECT COUNT(*) FROM {$this->jobs_table}";
162 162
 		
163
-		return (int) $this->database->get_var( $sql );
163
+		return (int) $this->database->get_var($sql);
164 164
 	}
165 165
 
166 166
 	/**
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
 	public function failed_jobs() {
172 172
 		$sql = "SELECT COUNT(*) FROM {$this->failures_table}";
173 173
 
174
-		return (int) $this->database->get_var( $sql );
174
+		return (int) $this->database->get_var($sql);
175 175
 	}
176 176
 
177 177
 	/**
@@ -179,14 +179,14 @@  discard block
 block discarded – undo
179 179
 	 *
180 180
 	 * @param Job $job
181 181
 	 */
182
-	protected function reserve( $job ) {
182
+	protected function reserve($job) {
183 183
 		$data = array(
184 184
 			'reserved_at' => $this->datetime(),
185 185
 		);
186 186
 
187
-		$this->database->update( $this->jobs_table, $data, array(
187
+		$this->database->update($this->jobs_table, $data, array(
188 188
 			'id' => $job->id(),
189
-		) );
189
+		));
190 190
 	}
191 191
 
192 192
 	/**
@@ -195,12 +195,12 @@  discard block
 block discarded – undo
195 195
 	protected function release_reserved() {
196 196
 		$expired = $this->datetime( -300 );
197 197
 
198
-		$sql = $this->database->prepare( "
198
+		$sql = $this->database->prepare("
199 199
 				UPDATE {$this->jobs_table}
200 200
 				SET attempts = attempts + 1, reserved_at = NULL
201
-				WHERE reserved_at <= %s", $expired );
201
+				WHERE reserved_at <= %s", $expired);
202 202
 
203
-		$this->database->query( $sql );
203
+		$this->database->query($sql);
204 204
 	}
205 205
 
206 206
 	/**
@@ -210,14 +210,14 @@  discard block
 block discarded – undo
210 210
 	 *
211 211
 	 * @return Job
212 212
 	 */
213
-	protected function vitalize_job( $raw_job ) {
214
-		$job = unserialize( $raw_job->job );
213
+	protected function vitalize_job($raw_job) {
214
+		$job = unserialize($raw_job->job);
215 215
 
216
-		$job->set_id( $raw_job->id );
217
-		$job->set_attempts( $raw_job->attempts );
218
-		$job->set_reserved_at( empty( $raw_job->reserved_at ) ? null : new Carbon( $raw_job->reserved_at ) );
219
-		$job->set_available_at( new Carbon( $raw_job->available_at ) );
220
-		$job->set_created_at( new Carbon( $raw_job->created_at ) );
216
+		$job->set_id($raw_job->id);
217
+		$job->set_attempts($raw_job->attempts);
218
+		$job->set_reserved_at(empty($raw_job->reserved_at) ? null : new Carbon($raw_job->reserved_at));
219
+		$job->set_available_at(new Carbon($raw_job->available_at));
220
+		$job->set_created_at(new Carbon($raw_job->created_at));
221 221
 
222 222
 		return $job;
223 223
 	}
@@ -229,10 +229,10 @@  discard block
 block discarded – undo
229 229
 	 *
230 230
 	 * @return string
231 231
 	 */
232
-	protected function datetime( $offset = 0 ) {
232
+	protected function datetime($offset = 0) {
233 233
 		$timestamp = time() + $offset;
234 234
 
235
-		return gmdate( 'Y-m-d H:i:s', $timestamp );
235
+		return gmdate('Y-m-d H:i:s', $timestamp);
236 236
 	}
237 237
 
238 238
 	/**
@@ -242,14 +242,14 @@  discard block
 block discarded – undo
242 242
 	 *
243 243
 	 * @return string
244 244
 	 */
245
-	protected function format_exception( Exception $exception ) {
246
-		$string = get_class( $exception );
245
+	protected function format_exception(Exception $exception) {
246
+		$string = get_class($exception);
247 247
 
248
-		if ( ! empty( $exception->getMessage() ) ) {
248
+		if ( ! empty($exception->getMessage())) {
249 249
 			$string .= " : {$exception->getMessage()}";
250 250
 		}
251 251
 
252
-		if ( ! empty( $exception->getCode() ) ) {
252
+		if ( ! empty($exception->getCode())) {
253 253
 			$string .= " (#{$exception->getCode()})";
254 254
 		}
255 255
 
Please login to merge, or discard this patch.
src/WP_Queue/Connections/ConnectionInterface.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
 	 *
16 16
 	 * @return bool|int
17 17
 	 */
18
-	public function push( Job $job, $delay = 0 );
18
+	public function push(Job $job, $delay = 0);
19 19
 
20 20
 	/**
21 21
 	 * Retrieve a job from the queue.
@@ -29,14 +29,14 @@  discard block
 block discarded – undo
29 29
 	 *
30 30
 	 * @param Job $job
31 31
 	 */
32
-	public function delete( $job );
32
+	public function delete($job);
33 33
 
34 34
 	/**
35 35
 	 * Release a job back onto the queue.
36 36
 	 *
37 37
 	 * @param Job $job
38 38
 	 */
39
-	public function release( $job );
39
+	public function release($job);
40 40
 
41 41
 	/**
42 42
 	 * Push a job onto the failure queue.
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
 	 *
47 47
 	 * @return bool
48 48
 	 */
49
-	public function failure( $job, Exception $exception );
49
+	public function failure($job, Exception $exception);
50 50
 
51 51
 	/**
52 52
 	 * Get total jobs in the queue.
Please login to merge, or discard this patch.
src/WP_Queue/Connections/RedisConnection.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
 	 *
16 16
 	 * @return bool|int
17 17
 	 */
18
-	public function push( Job $job, $delay = 0 ) {
18
+	public function push(Job $job, $delay = 0) {
19 19
 		//
20 20
 	}
21 21
 
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
 	 *
34 34
 	 * @param Job $job
35 35
 	 */
36
-	public function delete( $job ) {
36
+	public function delete($job) {
37 37
 		//
38 38
 	}
39 39
 
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
 	 *
43 43
 	 * @param Job $job
44 44
 	 */
45
-	public function release( $job ) {
45
+	public function release($job) {
46 46
 		//
47 47
 	}
48 48
 
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
 	 *
55 55
 	 * @return bool
56 56
 	 */
57
-	public function failure( $job, Exception $exception ) {
57
+	public function failure($job, Exception $exception) {
58 58
 		//
59 59
 	}
60 60
 
Please login to merge, or discard this patch.
src/WP_Queue/QueueManager.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -22,12 +22,12 @@  discard block
 block discarded – undo
22 22
 	 * @return Queue
23 23
 	 * @throws \Exception
24 24
 	 */
25
-	public static function resolve( $connection ) {
26
-		if ( isset( static::$instances[ $connection ] ) ) {
27
-			return static::$instances[ $connection ];
25
+	public static function resolve($connection) {
26
+		if (isset(static::$instances[$connection])) {
27
+			return static::$instances[$connection];
28 28
 		}
29 29
 
30
-		return static::build( $connection );
30
+		return static::build($connection);
31 31
 	}
32 32
 
33 33
 	/**
@@ -38,16 +38,16 @@  discard block
 block discarded – undo
38 38
 	 * @return Queue
39 39
 	 * @throws \Exception
40 40
 	 */
41
-	protected static function build( $connection ) {
41
+	protected static function build($connection) {
42 42
 		$connections = static::connections();
43 43
 
44
-		if ( empty( $connections[ $connection ] ) ) {
44
+		if (empty($connections[$connection])) {
45 45
 			throw new ConnectionNotFoundException();
46 46
 		}
47 47
 
48
-		static::$instances[ $connection ] = new Queue( $connections[ $connection ] );
48
+		static::$instances[$connection] = new Queue($connections[$connection]);
49 49
 
50
-		return static::$instances[ $connection ];
50
+		return static::$instances[$connection];
51 51
 	}
52 52
 
53 53
 	/**
@@ -57,11 +57,11 @@  discard block
 block discarded – undo
57 57
 	 */
58 58
 	protected static function connections() {
59 59
 		$connections = array(
60
-			'database' => new DatabaseConnection( $GLOBALS['wpdb'] ),
60
+			'database' => new DatabaseConnection($GLOBALS['wpdb']),
61 61
 			'redis'    => new RedisConnection(),
62 62
 			'sync'     => new SyncConnection(),
63 63
 		);
64 64
 
65
-		return apply_filters( 'wp_queue_connections', $connections );
65
+		return apply_filters('wp_queue_connections', $connections);
66 66
 	}
67 67
 }
68 68
\ No newline at end of file
Please login to merge, or discard this patch.
src/functions.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@  discard block
 block discarded – undo
3 3
 use WP_Queue\Queue;
4 4
 use WP_Queue\QueueManager;
5 5
 
6
-if ( ! function_exists( 'wp_queue' ) ) {
6
+if ( ! function_exists('wp_queue')) {
7 7
 	/**
8 8
 	 * Return Queue instance.
9 9
 	 *
@@ -12,23 +12,23 @@  discard block
 block discarded – undo
12 12
 	 * @return Queue
13 13
 	 * @throws Exception
14 14
 	 */
15
-	function wp_queue( $connection = '' ) {
16
-		if( empty( $connection ) ) {
17
-			$connection = apply_filters( 'wp_queue_default_connection', 'database' );
15
+	function wp_queue($connection = '') {
16
+		if (empty($connection)) {
17
+			$connection = apply_filters('wp_queue_default_connection', 'database');
18 18
 		}
19 19
 		
20
-		return QueueManager::resolve( $connection );
20
+		return QueueManager::resolve($connection);
21 21
 	}
22 22
 }
23 23
 
24
-if ( ! function_exists( 'wp_queue_install_tables' ) ) {
24
+if ( ! function_exists('wp_queue_install_tables')) {
25 25
 	/**
26 26
 	 * Install database tables
27 27
 	 */
28 28
 	function wp_queue_install_tables() {
29 29
 		global $wpdb;
30 30
 
31
-		require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
31
+		require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
32 32
 
33 33
 		$wpdb->hide_errors();
34 34
 		$charset_collate = $wpdb->get_charset_collate();
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
 				PRIMARY KEY  (id)
44 44
 				) $charset_collate;";
45 45
 
46
-		dbDelta( $sql );
46
+		dbDelta($sql);
47 47
 
48 48
 		$sql = "CREATE TABLE {$wpdb->prefix}queue_failures (
49 49
 				id bigint(20) NOT NULL AUTO_INCREMENT,
@@ -53,6 +53,6 @@  discard block
 block discarded – undo
53 53
 				PRIMARY KEY  (id)
54 54
 				) $charset_collate;";
55 55
 
56
-		dbDelta( $sql );
56
+		dbDelta($sql);
57 57
 	}
58 58
 }
59 59
\ No newline at end of file
Please login to merge, or discard this patch.