Passed
Push — master ( c19952...395ece )
by Ashley
03:21
created
src/WP_Queue/Worker.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 	 * @param ConnectionInterface $connection
25 25
 	 * @param int                 $attempts
26 26
 	 */
27
-	public function __construct( $connection, $attempts = 3 ) {
27
+	public function __construct($connection, $attempts = 3) {
28 28
 		$this->connection = $connection;
29 29
 		$this->attempts   = $attempts;
30 30
 	}
@@ -37,7 +37,7 @@  discard block
 block discarded – undo
37 37
 	public function process() {
38 38
 		$job = $this->connection->pop();
39 39
 
40
-		if ( ! $job ) {
40
+		if ( ! $job) {
41 41
 			return false;
42 42
 		}
43 43
 
@@ -45,24 +45,24 @@  discard block
 block discarded – undo
45 45
 
46 46
 		try {
47 47
 			$job->handle();
48
-		} catch ( Exception $exception ) {
48
+		} catch (Exception $exception) {
49 49
 			$job->release();
50 50
 		}
51 51
 
52
-		if ( $job->attempts() >= $this->attempts ) {
53
-			if ( empty( $exception ) ) {
52
+		if ($job->attempts() >= $this->attempts) {
53
+			if (empty($exception)) {
54 54
 				$exception = new WorkerAttemptsExceededException();
55 55
 			}
56 56
 			
57 57
 			$job->fail();
58 58
 		}
59 59
 
60
-		if ( $job->failed() ) {
61
-			$this->connection->failure( $job, $exception );
62
-		} else if ( $job->released() ) {
63
-			$this->connection->release( $job );
60
+		if ($job->failed()) {
61
+			$this->connection->failure($job, $exception);
62
+		} else if ($job->released()) {
63
+			$this->connection->release($job);
64 64
 		} else {
65
-			$this->connection->delete( $job );
65
+			$this->connection->delete($job);
66 66
 		}
67 67
 
68 68
 		return true;
Please login to merge, or discard this patch.
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.