Passed
Pull Request — master (#13)
by
unknown
02:41
created
demo/job.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -3,7 +3,7 @@
 block discarded – undo
3 3
 {
4 4
 	public function perform()
5 5
 	{
6
-        fwrite(STDOUT, 'Start job! -> ');
6
+		fwrite(STDOUT, 'Start job! -> ');
7 7
 		sleep(1);
8 8
 		fwrite(STDOUT, 'Job ended!' . PHP_EOL);
9 9
 	}
Please login to merge, or discard this patch.
demo/check_status.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if(empty($argv[1])) {
2
+if (empty($argv[1])) {
3 3
 	die('Specify the ID of a job to monitor the status of.');
4 4
 }
5 5
 
@@ -12,12 +12,12 @@  discard block
 block discarded – undo
12 12
 //Resque::setBackend('redis://user:[email protected]:3432/2');
13 13
 
14 14
 $status = new Resque_Job_Status($argv[1]);
15
-if(!$status->isTracking()) {
15
+if (!$status->isTracking()) {
16 16
 	die("Resque is not tracking the status of this job.\n");
17 17
 }
18 18
 
19
-echo "Tracking status of ".$argv[1].". Press [break] to stop.\n\n";
20
-while(true) {
21
-	fwrite(STDOUT, "Status of ".$argv[1]." is: ".$status->get()."\n");
19
+echo "Tracking status of " . $argv[1] . ". Press [break] to stop.\n\n";
20
+while (true) {
21
+	fwrite(STDOUT, "Status of " . $argv[1] . " is: " . $status->get() . "\n");
22 22
 	sleep(1);
23 23
 }
24 24
\ No newline at end of file
Please login to merge, or discard this patch.
demo/queue.php 2 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@
 block discarded – undo
20 20
 if (empty($argv[2])) {
21 21
 	$jobId = Resque::enqueue('default', $argv[1], $args, true);
22 22
 } else {
23
-        $jobId = Resque::enqueue($argv[1], $argv[2], $args, true);	
23
+		$jobId = Resque::enqueue($argv[1], $argv[2], $args, true);	
24 24
 }
25 25
 
26 26
 echo "Queued job ".$jobId."\n\n";
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if(empty($argv[1])) {
2
+if (empty($argv[1])) {
3 3
 	die('Specify the name of a job to add. e.g, php queue.php PHP_Job');
4 4
 }
5 5
 
@@ -23,4 +23,4 @@  discard block
 block discarded – undo
23 23
         $jobId = Resque::enqueue($argv[1], $argv[2], $args, true);	
24 24
 }
25 25
 
26
-echo "Queued job ".$jobId."\n\n";
26
+echo "Queued job " . $jobId . "\n\n";
Please login to merge, or discard this patch.
lib/Resque.php 3 patches
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
 {
11 11
 	const VERSION = '1.2';
12 12
 
13
-    const DEFAULT_INTERVAL = 5;
13
+	const DEFAULT_INTERVAL = 5;
14 14
 
15 15
 	/**
16 16
 	 * @var Resque_Redis Instance of Resque_Redis that talks to redis.
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
 	 */
123 123
 	public static function pop($queue)
124 124
 	{
125
-        $item = self::redis()->lpop('queue:' . $queue);
125
+		$item = self::redis()->lpop('queue:' . $queue);
126 126
 
127 127
 		if(!$item) {
128 128
 			return;
@@ -140,11 +140,11 @@  discard block
 block discarded – undo
140 140
 	 */
141 141
 	public static function dequeue($queue, $items = Array())
142 142
 	{
143
-	    if(count($items) > 0) {
143
+		if(count($items) > 0) {
144 144
 		return self::removeItems($queue, $items);
145
-	    } else {
145
+		} else {
146 146
 		return self::removeList($queue);
147
-	    }
147
+		}
148 148
 	}
149 149
 
150 150
 	/**
@@ -155,9 +155,9 @@  discard block
 block discarded – undo
155 155
 	 */
156 156
 	public static function removeQueue($queue)
157 157
 	{
158
-	    $num = self::removeList($queue);
159
-	    self::redis()->srem('queues', $queue);
160
-	    return $num;
158
+		$num = self::removeList($queue);
159
+		self::redis()->srem('queues', $queue);
160
+		return $num;
161 161
 	}
162 162
 
163 163
 	/**
@@ -170,28 +170,28 @@  discard block
 block discarded – undo
170 170
 	 */
171 171
 	public static function blpop(array $queues, $timeout)
172 172
 	{
173
-	    $list = array();
174
-	    foreach($queues AS $queue) {
173
+		$list = array();
174
+		foreach($queues AS $queue) {
175 175
 		$list[] = 'queue:' . $queue;
176
-	    }
176
+		}
177 177
 
178
-	    $item = self::redis()->blpop($list, (int)$timeout);
178
+		$item = self::redis()->blpop($list, (int)$timeout);
179 179
 
180
-	    if(!$item) {
180
+		if(!$item) {
181 181
 		return;
182
-	    }
182
+		}
183 183
 
184
-	    /**
185
-	     * Normally the Resque_Redis class returns queue names without the prefix
186
-	     * But the blpop is a bit different. It returns the name as prefix:queue:name
187
-	     * So we need to strip off the prefix:queue: part
188
-	     */
189
-	    $queue = substr($item[0], strlen(self::redis()->getPrefix() . 'queue:'));
184
+		/**
185
+		 * Normally the Resque_Redis class returns queue names without the prefix
186
+		 * But the blpop is a bit different. It returns the name as prefix:queue:name
187
+		 * So we need to strip off the prefix:queue: part
188
+		 */
189
+		$queue = substr($item[0], strlen(self::redis()->getPrefix() . 'queue:'));
190 190
 
191
-	    return array(
191
+		return array(
192 192
 		'queue'   => $queue,
193 193
 		'payload' => json_decode($item[1], true)
194
-	    );
194
+		);
195 195
 	}
196 196
 
197 197
 	/**
@@ -304,7 +304,7 @@  discard block
 block discarded – undo
304 304
 		while (!$finished) {
305 305
 			$string = self::redis()->rpoplpush($requeueQueue, self::redis()->getPrefix() .$originalQueue);
306 306
 			if (empty($string)) {
307
-			    $finished = true;
307
+				$finished = true;
308 308
 			}
309 309
 		}
310 310
 
@@ -327,29 +327,29 @@  discard block
 block discarded – undo
327 327
 	 */
328 328
 	private static function matchItem($string, $items)
329 329
 	{
330
-	    $decoded = json_decode($string, true);
330
+		$decoded = json_decode($string, true);
331 331
 
332
-	    foreach($items as $key => $val) {
332
+		foreach($items as $key => $val) {
333 333
 		# class name only  ex: item[0] = ['class']
334 334
 		if (is_numeric($key)) {
335
-		    if($decoded['class'] == $val) {
335
+			if($decoded['class'] == $val) {
336 336
 			return true;
337
-		    }
337
+			}
338 338
 		# class name with args , example: item[0] = ['class' => {'foo' => 1, 'bar' => 2}]
339
-    		} elseif (is_array($val)) {
340
-		    $decodedArgs = (array)$decoded['args'][0];
341
-		    if ($decoded['class'] == $key &&
339
+			} elseif (is_array($val)) {
340
+			$decodedArgs = (array)$decoded['args'][0];
341
+			if ($decoded['class'] == $key &&
342 342
 			count($decodedArgs) > 0 && count(array_diff($decodedArgs, $val)) == 0) {
343 343
 			return true;
344 344
 			}
345 345
 		# class name with ID, example: item[0] = ['class' => 'id']
346 346
 		} else {
347
-		    if ($decoded['class'] == $key && $decoded['id'] == $val) {
347
+			if ($decoded['class'] == $key && $decoded['id'] == $val) {
348 348
 			return true;
349
-		    }
349
+			}
350
+		}
350 351
 		}
351
-	    }
352
-	    return false;
352
+		return false;
353 353
 	}
354 354
 
355 355
 	/**
@@ -362,9 +362,9 @@  discard block
 block discarded – undo
362 362
 	 */
363 363
 	private static function removeList($queue)
364 364
 	{
365
-	    $counter = self::size($queue);
366
-	    $result = self::redis()->del('queue:' . $queue);
367
-	    return ($result == 1) ? $counter : 0;
365
+		$counter = self::size($queue);
366
+		$result = self::redis()->del('queue:' . $queue);
367
+		return ($result == 1) ? $counter : 0;
368 368
 	}
369 369
 
370 370
 	/*
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
 	 */
77 77
 	public static function fork()
78 78
 	{
79
-		if(!function_exists('pcntl_fork')) {
79
+		if (!function_exists('pcntl_fork')) {
80 80
 			return false;
81 81
 		}
82 82
 
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
 		self::$redis = null;
86 86
 
87 87
 		$pid = pcntl_fork();
88
-		if($pid === -1) {
88
+		if ($pid === -1) {
89 89
 			throw new RuntimeException('Unable to fork child worker.');
90 90
 		}
91 91
 
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
 	{
125 125
         $item = self::redis()->lpop('queue:' . $queue);
126 126
 
127
-		if(!$item) {
127
+		if (!$item) {
128 128
 			return;
129 129
 		}
130 130
 
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
 	 */
141 141
 	public static function dequeue($queue, $items = Array())
142 142
 	{
143
-	    if(count($items) > 0) {
143
+	    if (count($items) > 0) {
144 144
 		return self::removeItems($queue, $items);
145 145
 	    } else {
146 146
 		return self::removeList($queue);
@@ -171,13 +171,13 @@  discard block
 block discarded – undo
171 171
 	public static function blpop(array $queues, $timeout)
172 172
 	{
173 173
 	    $list = array();
174
-	    foreach($queues AS $queue) {
174
+	    foreach ($queues AS $queue) {
175 175
 		$list[] = 'queue:' . $queue;
176 176
 	    }
177 177
 
178 178
 	    $item = self::redis()->blpop($list, (int)$timeout);
179 179
 
180
-	    if(!$item) {
180
+	    if (!$item) {
181 181
 		return;
182 182
 	    }
183 183
 
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
 		try {
229 229
 			Resque_Event::trigger('beforeEnqueue', $hookParams);
230 230
 		}
231
-		catch(Resque_Job_DontCreate $e) {
231
+		catch (Resque_Job_DontCreate $e) {
232 232
 			return false;
233 233
 		}
234 234
 
@@ -257,7 +257,7 @@  discard block
 block discarded – undo
257 257
 	public static function queues()
258 258
 	{
259 259
 		$queues = self::redis()->smembers('queues');
260
-		if(!is_array($queues)) {
260
+		if (!is_array($queues)) {
261 261
 			$queues = array();
262 262
 		}
263 263
 		return $queues;
@@ -278,9 +278,9 @@  discard block
 block discarded – undo
278 278
 	private static function removeItems($queue, $items = Array())
279 279
 	{
280 280
 		$counter = 0;
281
-		$originalQueue = 'queue:'. $queue;
282
-		$tempQueue = $originalQueue. ':temp:'. time();
283
-		$requeueQueue = $tempQueue. ':requeue';
281
+		$originalQueue = 'queue:' . $queue;
282
+		$tempQueue = $originalQueue . ':temp:' . time();
283
+		$requeueQueue = $tempQueue . ':requeue';
284 284
 
285 285
 		// move each item from original queue to temp queue and process it
286 286
 		$finished = false;
@@ -288,7 +288,7 @@  discard block
 block discarded – undo
288 288
 			$string = self::redis()->rpoplpush($originalQueue, self::redis()->getPrefix() . $tempQueue);
289 289
 
290 290
 			if (!empty($string)) {
291
-				if(self::matchItem($string, $items)) {
291
+				if (self::matchItem($string, $items)) {
292 292
 					self::redis()->rpop($tempQueue);
293 293
 					$counter++;
294 294
 				} else {
@@ -302,7 +302,7 @@  discard block
 block discarded – undo
302 302
 		// move back from temp queue to original queue
303 303
 		$finished = false;
304 304
 		while (!$finished) {
305
-			$string = self::redis()->rpoplpush($requeueQueue, self::redis()->getPrefix() .$originalQueue);
305
+			$string = self::redis()->rpoplpush($requeueQueue, self::redis()->getPrefix() . $originalQueue);
306 306
 			if (empty($string)) {
307 307
 			    $finished = true;
308 308
 			}
@@ -329,10 +329,10 @@  discard block
 block discarded – undo
329 329
 	{
330 330
 	    $decoded = json_decode($string, true);
331 331
 
332
-	    foreach($items as $key => $val) {
332
+	    foreach ($items as $key => $val) {
333 333
 		# class name only  ex: item[0] = ['class']
334 334
 		if (is_numeric($key)) {
335
-		    if($decoded['class'] == $val) {
335
+		    if ($decoded['class'] == $val) {
336 336
 			return true;
337 337
 		    }
338 338
 		# class name with args , example: item[0] = ['class' => {'foo' => 1, 'bar' => 2}]
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -227,8 +227,7 @@
 block discarded – undo
227 227
 		);
228 228
 		try {
229 229
 			Resque_Event::trigger('beforeEnqueue', $hookParams);
230
-		}
231
-		catch(Resque_Job_DontCreate $e) {
230
+		} catch(Resque_Job_DontCreate $e) {
232 231
 			return false;
233 232
 		}
234 233
 
Please login to merge, or discard this patch.
lib/Resque/Job.php 2 patches
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -169,9 +169,9 @@  discard block
 block discarded – undo
169 169
 			return $this->instance;
170 170
 		}
171 171
 
172
-        $this->instance = $this->getJobFactory()->create($this->payload['class'], $this->getArguments(), $this->queue);
173
-        $this->instance->job = $this;
174
-        return $this->instance;
172
+		$this->instance = $this->getJobFactory()->create($this->payload['class'], $this->getArguments(), $this->queue);
173
+		$this->instance->job = $this;
174
+		return $this->instance;
175 175
 	}
176 176
 
177 177
 	/**
@@ -276,14 +276,14 @@  discard block
 block discarded – undo
276 276
 		return $this;
277 277
 	}
278 278
 
279
-    /**
280
-     * @return Resque_Job_FactoryInterface
281
-     */
282
-    public function getJobFactory()
283
-    {
284
-        if ($this->jobFactory === null) {
285
-            $this->jobFactory = new Resque_Job_Factory();
286
-        }
287
-        return $this->jobFactory;
288
-    }
279
+	/**
280
+	 * @return Resque_Job_FactoryInterface
281
+	 */
282
+	public function getJobFactory()
283
+	{
284
+		if ($this->jobFactory === null) {
285
+			$this->jobFactory = new Resque_Job_Factory();
286
+		}
287
+		return $this->jobFactory;
288
+	}
289 289
 }
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
 			$id = Resque::generateJobId();
64 64
 		}
65 65
 
66
-		if($args !== null && !is_array($args)) {
66
+		if ($args !== null && !is_array($args)) {
67 67
 			throw new InvalidArgumentException(
68 68
 				'Supplied $args must be an array.'
69 69
 			);
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
 			'queue_time' => microtime(true),
76 76
 		));
77 77
 
78
-		if($monitor) {
78
+		if ($monitor) {
79 79
 			Resque_Job_Status::create($id);
80 80
 		}
81 81
 
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
 	public static function reserve($queue)
93 93
 	{
94 94
 		$payload = Resque::pop($queue);
95
-		if(!is_array($payload)) {
95
+		if (!is_array($payload)) {
96 96
 			return false;
97 97
 		}
98 98
 
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
 	{
112 112
 		$item = Resque::blpop($queues, $timeout);
113 113
 
114
-		if(!is_array($item)) {
114
+		if (!is_array($item)) {
115 115
 			return false;
116 116
 		}
117 117
 
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
 	 */
126 126
 	public function updateStatus($status)
127 127
 	{
128
-		if(empty($this->payload['id'])) {
128
+		if (empty($this->payload['id'])) {
129 129
 			return;
130 130
 		}
131 131
 
@@ -187,20 +187,20 @@  discard block
 block discarded – undo
187 187
 			Resque_Event::trigger('beforePerform', $this);
188 188
 
189 189
 			$instance = $this->getInstance();
190
-			if(method_exists($instance, 'setUp')) {
190
+			if (method_exists($instance, 'setUp')) {
191 191
 				$instance->setUp();
192 192
 			}
193 193
 
194 194
 			$instance->perform();
195 195
 
196
-			if(method_exists($instance, 'tearDown')) {
196
+			if (method_exists($instance, 'tearDown')) {
197 197
 				$instance->tearDown();
198 198
 			}
199 199
 
200 200
 			Resque_Event::trigger('afterPerform', $this);
201 201
 		}
202 202
 		// beforePerform/setUp have said don't perform this job. Return.
203
-		catch(Resque_Job_DontPerform $e) {
203
+		catch (Resque_Job_DontPerform $e) {
204 204
 			return false;
205 205
 		}
206 206
 
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
 	{
239 239
 		$status = new Resque_Job_Status($this->payload['id']);
240 240
 		$monitor = false;
241
-		if($status->isTracking()) {
241
+		if ($status->isTracking()) {
242 242
 			$monitor = true;
243 243
 		}
244 244
 
@@ -253,13 +253,13 @@  discard block
 block discarded – undo
253 253
 	public function __toString()
254 254
 	{
255 255
 		$name = array(
256
-			'Job{' . $this->queue .'}'
256
+			'Job{' . $this->queue . '}'
257 257
 		);
258
-		if(!empty($this->payload['id'])) {
258
+		if (!empty($this->payload['id'])) {
259 259
 			$name[] = 'ID: ' . $this->payload['id'];
260 260
 		}
261 261
 		$name[] = $this->payload['class'];
262
-		if(!empty($this->payload['args'])) {
262
+		if (!empty($this->payload['args'])) {
263 263
 			$name[] = json_encode($this->payload['args']);
264 264
 		}
265 265
 		return '(' . implode(' | ', $name) . ')';
Please login to merge, or discard this patch.
lib/Resque/Worker.php 3 patches
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -12,8 +12,8 @@  discard block
 block discarded – undo
12 12
 class Resque_Worker
13 13
 {
14 14
 	/**
15
-	* @var LoggerInterface Logging object that impliments the PSR-3 LoggerInterface
16
-	*/
15
+	 * @var LoggerInterface Logging object that impliments the PSR-3 LoggerInterface
16
+	 */
17 17
 	public $logger;
18 18
 
19 19
 	/**
@@ -56,30 +56,30 @@  discard block
 block discarded – undo
56 56
 	 */
57 57
 	private $child = null;
58 58
 
59
-    /**
60
-     * Instantiate a new worker, given a list of queues that it should be working
61
-     * on. The list of queues should be supplied in the priority that they should
62
-     * be checked for jobs (first come, first served)
63
-     *
64
-     * Passing a single '*' allows the worker to work on all queues in alphabetical
65
-     * order. You can easily add new queues dynamically and have them worked on using
66
-     * this method.
67
-     *
68
-     * @param string|array $queues String with a single queue name, array with multiple.
69
-     */
70
-    public function __construct($queues)
71
-    {
72
-        $this->logger = new Resque_Log();
73
-
74
-        if(!is_array($queues)) {
75
-            $queues = array($queues);
76
-        }
77
-
78
-        $this->queues = $queues;
79
-        $this->hostname = php_uname('n');
80
-
81
-        $this->id = $this->hostname . ':'.getmypid() . ':' . implode(',', $this->queues);
82
-    }
59
+	/**
60
+	 * Instantiate a new worker, given a list of queues that it should be working
61
+	 * on. The list of queues should be supplied in the priority that they should
62
+	 * be checked for jobs (first come, first served)
63
+	 *
64
+	 * Passing a single '*' allows the worker to work on all queues in alphabetical
65
+	 * order. You can easily add new queues dynamically and have them worked on using
66
+	 * this method.
67
+	 *
68
+	 * @param string|array $queues String with a single queue name, array with multiple.
69
+	 */
70
+	public function __construct($queues)
71
+	{
72
+		$this->logger = new Resque_Log();
73
+
74
+		if(!is_array($queues)) {
75
+			$queues = array($queues);
76
+		}
77
+
78
+		$this->queues = $queues;
79
+		$this->hostname = php_uname('n');
80
+
81
+		$this->id = $this->hostname . ':'.getmypid() . ':' . implode(',', $this->queues);
82
+	}
83 83
 
84 84
 	/**
85 85
 	 * Return all workers known to Resque as instantiated instances.
Please login to merge, or discard this patch.
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-declare(ticks = 1);
2
+declare(ticks=1);
3 3
 
4 4
 /**
5 5
  * Resque worker that handles checking queues for jobs, fetching them
@@ -71,14 +71,14 @@  discard block
 block discarded – undo
71 71
     {
72 72
         $this->logger = new Resque_Log();
73 73
 
74
-        if(!is_array($queues)) {
74
+        if (!is_array($queues)) {
75 75
             $queues = array($queues);
76 76
         }
77 77
 
78 78
         $this->queues = $queues;
79 79
         $this->hostname = php_uname('n');
80 80
 
81
-        $this->id = $this->hostname . ':'.getmypid() . ':' . implode(',', $this->queues);
81
+        $this->id = $this->hostname . ':' . getmypid() . ':' . implode(',', $this->queues);
82 82
     }
83 83
 
84 84
 	/**
@@ -88,12 +88,12 @@  discard block
 block discarded – undo
88 88
 	public static function all()
89 89
 	{
90 90
 		$workers = Resque::redis()->smembers('workers');
91
-		if(!is_array($workers)) {
91
+		if (!is_array($workers)) {
92 92
 			$workers = array();
93 93
 		}
94 94
 
95 95
 		$instances = array();
96
-		foreach($workers as $workerId) {
96
+		foreach ($workers as $workerId) {
97 97
 			$instances[] = self::find($workerId);
98 98
 		}
99 99
 		return $instances;
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
 	 */
119 119
 	public static function find($workerId)
120 120
 	{
121
-		if(!self::exists($workerId) || false === strpos($workerId, ":")) {
121
+		if (!self::exists($workerId) || false === strpos($workerId, ":")) {
122 122
 			return false;
123 123
 		}
124 124
 
@@ -152,15 +152,15 @@  discard block
 block discarded – undo
152 152
 		$this->updateProcLine('Starting');
153 153
 		$this->startup();
154 154
 
155
-		while(true) {
156
-			if($this->shutdown) {
155
+		while (true) {
156
+			if ($this->shutdown) {
157 157
 				break;
158 158
 			}
159 159
 
160 160
 			// Attempt to find and reserve a job
161 161
 			$job = false;
162
-			if(!$this->paused) {
163
-				if($blocking === true) {
162
+			if (!$this->paused) {
163
+				if ($blocking === true) {
164 164
 					$this->logger->log(Psr\Log\LogLevel::INFO, 'Starting blocking with timeout of {interval}', array('interval' => $interval));
165 165
 					$this->updateProcLine('Waiting for ' . implode(',', $this->queues) . ' with blocking timeout ' . $interval);
166 166
 				} else {
@@ -170,17 +170,17 @@  discard block
 block discarded – undo
170 170
 				$job = $this->reserve($blocking, $interval);
171 171
 			}
172 172
 
173
-			if(!$job) {
173
+			if (!$job) {
174 174
 				// For an interval of 0, break now - helps with unit testing etc
175
-				if($interval == 0) {
175
+				if ($interval == 0) {
176 176
 					break;
177 177
 				}
178 178
 
179
-				if($blocking === false)
179
+				if ($blocking === false)
180 180
 				{
181 181
 					// If no job was found, we sleep for $interval before continuing and checking again
182 182
 					$this->logger->log(Psr\Log\LogLevel::INFO, 'Sleeping for {interval}', array('interval' => $interval));
183
-					if($this->paused) {
183
+					if ($this->paused) {
184 184
 						$this->updateProcLine('Paused');
185 185
 					}
186 186
 					else {
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
 				}
211 211
 			}
212 212
 
213
-			if($this->child > 0) {
213
+			if ($this->child > 0) {
214 214
 				// Parent process, sit and wait
215 215
 				$status = 'Forked ' . $this->child . ' at ' . strftime('%F %T');
216 216
 				$this->updateProcLine($status);
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
 			Resque_Event::trigger('afterFork', $job);
255 255
 			$job->perform();
256 256
 		}
257
-		catch(Exception $e) {
257
+		catch (Exception $e) {
258 258
 			$this->logger->log(Psr\Log\LogLevel::CRITICAL, '{job} has failed {stack}', array('job' => $job, 'stack' => $e));
259 259
 			$job->fail($e);
260 260
 			return;
@@ -278,21 +278,21 @@  discard block
 block discarded – undo
278 278
 		}
279 279
 
280 280
 		$queues = $this->queues();
281
-		if(!is_array($queues)) {
281
+		if (!is_array($queues)) {
282 282
 			return;
283 283
 		}
284 284
 
285
-		if($blocking === true) {
285
+		if ($blocking === true) {
286 286
 			$job = Resque_Job::reserveBlocking($queues, $timeout);
287
-			if($job) {
287
+			if ($job) {
288 288
 				$this->logger->log(Psr\Log\LogLevel::INFO, 'Found job on {queue}', array('queue' => $job->queue));
289 289
 				return $job;
290 290
 			}
291 291
 		} else {
292
-			foreach($queues as $queue) {
292
+			foreach ($queues as $queue) {
293 293
 				$this->logger->log(Psr\Log\LogLevel::INFO, 'Checking {queue} for jobs', array('queue' => $queue));
294 294
 				$job = Resque_Job::reserve($queue);
295
-				if($job) {
295
+				if ($job) {
296 296
 					$this->logger->log(Psr\Log\LogLevel::INFO, 'Found job on {queue}', array('queue' => $job->queue));
297 297
 					return $job;
298 298
 				}
@@ -315,7 +315,7 @@  discard block
 block discarded – undo
315 315
 	 */
316 316
 	public function queues($fetch = true)
317 317
 	{
318
-		if(!in_array('*', $this->queues) || $fetch == false) {
318
+		if (!in_array('*', $this->queues) || $fetch == false) {
319 319
 			return $this->queues;
320 320
 		}
321 321
 
@@ -345,10 +345,10 @@  discard block
 block discarded – undo
345 345
 	private function updateProcLine($status)
346 346
 	{
347 347
 		$processTitle = 'resque-' . Resque::VERSION . ': ' . $status;
348
-		if(function_exists('cli_set_process_title') && PHP_OS !== 'Darwin') {
348
+		if (function_exists('cli_set_process_title') && PHP_OS !== 'Darwin') {
349 349
 			cli_set_process_title($processTitle);
350 350
 		}
351
-		else if(function_exists('setproctitle')) {
351
+		else if (function_exists('setproctitle')) {
352 352
 			setproctitle($processTitle);
353 353
 		}
354 354
 	}
@@ -363,7 +363,7 @@  discard block
 block discarded – undo
363 363
 	 */
364 364
 	private function registerSigHandlers()
365 365
 	{
366
-		if(!function_exists('pcntl_signal')) {
366
+		if (!function_exists('pcntl_signal')) {
367 367
 			return;
368 368
 		}
369 369
 
@@ -421,13 +421,13 @@  discard block
 block discarded – undo
421 421
 	 */
422 422
 	public function killChild()
423 423
 	{
424
-		if(!$this->child) {
424
+		if (!$this->child) {
425 425
 			$this->logger->log(Psr\Log\LogLevel::DEBUG, 'No child to kill.');
426 426
 			return;
427 427
 		}
428 428
 
429 429
 		$this->logger->log(Psr\Log\LogLevel::INFO, 'Killing child at {child}', array('child' => $this->child));
430
-		if(exec('ps -o pid,state -p ' . $this->child, $output, $returnCode) && $returnCode != 1) {
430
+		if (exec('ps -o pid,state -p ' . $this->child, $output, $returnCode) && $returnCode != 1) {
431 431
 			$this->logger->log(Psr\Log\LogLevel::DEBUG, 'Child {child} found, killing.', array('child' => $this->child));
432 432
 			posix_kill($this->child, SIGKILL);
433 433
 			$this->child = null;
@@ -450,10 +450,10 @@  discard block
 block discarded – undo
450 450
 	{
451 451
 		$workerPids = $this->workerPids();
452 452
 		$workers = self::all();
453
-		foreach($workers as $worker) {
453
+		foreach ($workers as $worker) {
454 454
 			if (is_object($worker)) {
455 455
 				list($host, $pid, $queues) = explode(':', (string)$worker, 3);
456
-				if($host != $this->hostname || in_array($pid, $workerPids) || $pid == getmypid()) {
456
+				if ($host != $this->hostname || in_array($pid, $workerPids) || $pid == getmypid()) {
457 457
 					continue;
458 458
 				}
459 459
 				$this->logger->log(Psr\Log\LogLevel::INFO, 'Pruning dead worker: {worker}', array('worker' => (string)$worker));
@@ -472,7 +472,7 @@  discard block
 block discarded – undo
472 472
 	{
473 473
 		$pids = array();
474 474
 		exec('ps -A -o pid,command | grep [r]esque', $cmdOutput);
475
-		foreach($cmdOutput as $line) {
475
+		foreach ($cmdOutput as $line) {
476 476
 			list($pids[],) = explode(' ', trim($line), 2);
477 477
 		}
478 478
 		return $pids;
@@ -492,7 +492,7 @@  discard block
 block discarded – undo
492 492
 	 */
493 493
 	public function unregisterWorker()
494 494
 	{
495
-		if(is_object($this->currentJob)) {
495
+		if (is_object($this->currentJob)) {
496 496
 			$this->currentJob->fail(new Resque_Job_DirtyExitException);
497 497
 		}
498 498
 
@@ -552,7 +552,7 @@  discard block
 block discarded – undo
552 552
 	public function job()
553 553
 	{
554 554
 		$job = Resque::redis()->get('worker:' . $this);
555
-		if(!$job) {
555
+		if (!$job) {
556 556
 			return array();
557 557
 		}
558 558
 		else {
Please login to merge, or discard this patch.
Braces   +6 added lines, -12 removed lines patch added patch discarded remove patch
@@ -182,8 +182,7 @@  discard block
 block discarded – undo
182 182
 					$this->logger->log(Psr\Log\LogLevel::INFO, 'Sleeping for {interval}', array('interval' => $interval));
183 183
 					if($this->paused) {
184 184
 						$this->updateProcLine('Paused');
185
-					}
186
-					else {
185
+					} else {
187 186
 						$this->updateProcLine('Waiting for ' . implode(',', $this->queues));
188 187
 					}
189 188
 
@@ -225,8 +224,7 @@  discard block
 block discarded – undo
225 224
 					$job->fail(new Resque_Job_DirtyExitException(
226 225
 						'Job exited with exit code ' . $exitStatus
227 226
 					));
228
-				}
229
-				else
227
+				} else
230 228
 				{
231 229
 					if (in_array($job->getStatus(), array(Resque_Job_Status::STATUS_WAITING, Resque_Job_Status::STATUS_RUNNING)))
232 230
 					{
@@ -253,8 +251,7 @@  discard block
 block discarded – undo
253 251
 		try {
254 252
 			Resque_Event::trigger('afterFork', $job);
255 253
 			$job->perform();
256
-		}
257
-		catch(Exception $e) {
254
+		} catch(Exception $e) {
258 255
 			$this->logger->log(Psr\Log\LogLevel::CRITICAL, '{job} has failed {stack}', array('job' => $job, 'stack' => $e));
259 256
 			$job->fail($e);
260 257
 			return;
@@ -347,8 +344,7 @@  discard block
 block discarded – undo
347 344
 		$processTitle = 'resque-' . Resque::VERSION . ': ' . $status;
348 345
 		if(function_exists('cli_set_process_title') && PHP_OS !== 'Darwin') {
349 346
 			cli_set_process_title($processTitle);
350
-		}
351
-		else if(function_exists('setproctitle')) {
347
+		} else if(function_exists('setproctitle')) {
352 348
 			setproctitle($processTitle);
353 349
 		}
354 350
 	}
@@ -431,8 +427,7 @@  discard block
 block discarded – undo
431 427
 			$this->logger->log(Psr\Log\LogLevel::DEBUG, 'Child {child} found, killing.', array('child' => $this->child));
432 428
 			posix_kill($this->child, SIGKILL);
433 429
 			$this->child = null;
434
-		}
435
-		else {
430
+		} else {
436 431
 			$this->logger->log(Psr\Log\LogLevel::INFO, 'Child {child} not found, restarting.', array('child' => $this->child));
437 432
 			$this->shutdown();
438 433
 		}
@@ -554,8 +549,7 @@  discard block
 block discarded – undo
554 549
 		$job = Resque::redis()->get('worker:' . $this);
555 550
 		if(!$job) {
556 551
 			return array();
557
-		}
558
-		else {
552
+		} else {
559 553
 			return json_decode($job, true);
560 554
 		}
561 555
 	}
Please login to merge, or discard this patch.
lib/Resque/Job/Factory.php 1 patch
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -3,30 +3,30 @@
 block discarded – undo
3 3
 class Resque_Job_Factory implements Resque_Job_FactoryInterface
4 4
 {
5 5
 
6
-    /**
7
-     * @param $className
8
-     * @param array $args
9
-     * @param $queue
10
-     * @return Resque_JobInterface
11
-     * @throws \Resque_Exception
12
-     */
13
-    public function create($className, $args, $queue)
14
-    {
15
-        if (!class_exists($className)) {
16
-            throw new Resque_Exception(
17
-                'Could not find job class ' . $className . '.'
18
-            );
19
-        }
6
+	/**
7
+	 * @param $className
8
+	 * @param array $args
9
+	 * @param $queue
10
+	 * @return Resque_JobInterface
11
+	 * @throws \Resque_Exception
12
+	 */
13
+	public function create($className, $args, $queue)
14
+	{
15
+		if (!class_exists($className)) {
16
+			throw new Resque_Exception(
17
+				'Could not find job class ' . $className . '.'
18
+			);
19
+		}
20 20
 
21
-        if (!method_exists($className, 'perform')) {
22
-            throw new Resque_Exception(
23
-                'Job class ' . $className . ' does not contain a perform method.'
24
-            );
25
-        }
21
+		if (!method_exists($className, 'perform')) {
22
+			throw new Resque_Exception(
23
+				'Job class ' . $className . ' does not contain a perform method.'
24
+			);
25
+		}
26 26
 
27
-        $instance = new $className;
28
-        $instance->args = $args;
29
-        $instance->queue = $queue;
30
-        return $instance;
31
-    }
27
+		$instance = new $className;
28
+		$instance->args = $args;
29
+		$instance->queue = $queue;
30
+		return $instance;
31
+	}
32 32
 }
Please login to merge, or discard this patch.
lib/Resque/Job/Status.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -66,11 +66,11 @@  discard block
 block discarded – undo
66 66
 	 */
67 67
 	public function isTracking()
68 68
 	{
69
-		if($this->isTracking === false) {
69
+		if ($this->isTracking === false) {
70 70
 			return false;
71 71
 		}
72 72
 
73
-		if(!Resque::redis()->exists((string)$this)) {
73
+		if (!Resque::redis()->exists((string)$this)) {
74 74
 			$this->isTracking = false;
75 75
 			return false;
76 76
 		}
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
 	 */
87 87
 	public function update($status)
88 88
 	{
89
-		if(!$this->isTracking()) {
89
+		if (!$this->isTracking()) {
90 90
 			return;
91 91
 		}
92 92
 
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
 		Resque::redis()->set((string)$this, json_encode($statusPacket));
98 98
 
99 99
 		// Expire the status for completed jobs after 24 hours
100
-		if(in_array($status, self::$completeStatuses)) {
100
+		if (in_array($status, self::$completeStatuses)) {
101 101
 			Resque::redis()->expire((string)$this, 86400);
102 102
 		}
103 103
 	}
@@ -110,12 +110,12 @@  discard block
 block discarded – undo
110 110
 	 */
111 111
 	public function get()
112 112
 	{
113
-		if(!$this->isTracking()) {
113
+		if (!$this->isTracking()) {
114 114
 			return false;
115 115
 		}
116 116
 
117 117
 		$statusPacket = json_decode(Resque::redis()->get((string)$this), true);
118
-		if(!$statusPacket) {
118
+		if (!$statusPacket) {
119 119
 			return false;
120 120
 		}
121 121
 
Please login to merge, or discard this patch.
lib/Resque/Redis.php 3 patches
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -98,10 +98,10 @@  discard block
 block discarded – undo
98 98
 	 */
99 99
 	public static function prefix($namespace)
100 100
 	{
101
-	    if (substr($namespace, -1) !== ':' && $namespace != '') {
102
-	        $namespace .= ':';
103
-	    }
104
-	    self::$defaultNamespace = $namespace;
101
+		if (substr($namespace, -1) !== ':' && $namespace != '') {
102
+			$namespace .= ':';
103
+		}
104
+		self::$defaultNamespace = $namespace;
105 105
 	}
106 106
 
107 107
 	/**
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
 	 *                      DSN-supplied value will be used instead and this parameter is ignored.
111 111
 	 * @param object $client Optional Credis_Cluster or Credis_Client instance instantiated by you
112 112
 	 */
113
-    public function __construct($server, $database = null, $client = null)
113
+	public function __construct($server, $database = null, $client = null)
114 114
 	{
115 115
 		try {
116 116
 			if (is_array($server)) {
@@ -255,16 +255,16 @@  discard block
 block discarded – undo
255 255
 
256 256
 	public static function getPrefix()
257 257
 	{
258
-	    return self::$defaultNamespace;
258
+		return self::$defaultNamespace;
259 259
 	}
260 260
 
261 261
 	public static function removePrefix($string)
262 262
 	{
263
-	    $prefix=self::getPrefix();
263
+		$prefix=self::getPrefix();
264 264
 
265
-	    if (substr($string, 0, strlen($prefix)) == $prefix) {
266
-	        $string = substr($string, strlen($prefix), strlen($string) );
267
-	    }
268
-	    return $string;
265
+		if (substr($string, 0, strlen($prefix)) == $prefix) {
266
+			$string = substr($string, strlen($prefix), strlen($string) );
267
+		}
268
+		return $string;
269 269
 	}
270 270
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
 
131 131
 				$this->driver = new Credis_Client($host, $port, $timeout, $persistent);
132 132
 				$this->driver->setMaxConnectRetries($maxRetries);
133
-				if ($password){
133
+				if ($password) {
134 134
 					$this->driver->auth($password);
135 135
 				}
136 136
 
@@ -145,7 +145,7 @@  discard block
 block discarded – undo
145 145
 				$this->driver->select($database);
146 146
 			}
147 147
 		}
148
-		catch(CredisException $e) {
148
+		catch (CredisException $e) {
149 149
 			throw new Resque_RedisException('Error communicating with Redis: ' . $e->getMessage(), 0, $e);
150 150
 		}
151 151
 	}
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
 			// Use a sensible default for an empty DNS string
171 171
 			$dsn = 'redis://' . self::DEFAULT_HOST;
172 172
 		}
173
-		if(substr($dsn, 0, 7) === 'unix://') {
173
+		if (substr($dsn, 0, 7) === 'unix://') {
174 174
 			return array(
175 175
 				$dsn,
176 176
 				null,
@@ -184,12 +184,12 @@  discard block
 block discarded – undo
184 184
 
185 185
 		// Check the URI scheme
186 186
 		$validSchemes = array('redis', 'tcp');
187
-		if (isset($parts['scheme']) && ! in_array($parts['scheme'], $validSchemes)) {
187
+		if (isset($parts['scheme']) && !in_array($parts['scheme'], $validSchemes)) {
188 188
 			throw new \InvalidArgumentException("Invalid DSN. Supported schemes are " . implode(', ', $validSchemes));
189 189
 		}
190 190
 
191 191
 		// Allow simple 'hostname' format, which `parse_url` treats as a path, not host.
192
-		if ( ! isset($parts['host']) && isset($parts['path'])) {
192
+		if (!isset($parts['host']) && isset($parts['path'])) {
193 193
 			$parts['host'] = $parts['path'];
194 194
 			unset($parts['path']);
195 195
 		}
@@ -260,10 +260,10 @@  discard block
 block discarded – undo
260 260
 
261 261
 	public static function removePrefix($string)
262 262
 	{
263
-	    $prefix=self::getPrefix();
263
+	    $prefix = self::getPrefix();
264 264
 
265 265
 	    if (substr($string, 0, strlen($prefix)) == $prefix) {
266
-	        $string = substr($string, strlen($prefix), strlen($string) );
266
+	        $string = substr($string, strlen($prefix), strlen($string));
267 267
 	    }
268 268
 	    return $string;
269 269
 	}
Please login to merge, or discard this patch.
Braces   +5 added lines, -10 removed lines patch added patch discarded remove patch
@@ -115,11 +115,9 @@  discard block
 block discarded – undo
115 115
 		try {
116 116
 			if (is_array($server)) {
117 117
 				$this->driver = new Credis_Cluster($server);
118
-			}
119
-			else if (is_object($client)) {
118
+			} else if (is_object($client)) {
120 119
 				$this->driver = $client;
121
-			}
122
-			else {
120
+			} else {
123 121
 				list($host, $port, $dsnDatabase, $user, $password, $options) = self::parseDsn($server);
124 122
 				// $user is not used, only $password
125 123
 
@@ -144,8 +142,7 @@  discard block
 block discarded – undo
144 142
 			if ($database !== null) {
145 143
 				$this->driver->select($database);
146 144
 			}
147
-		}
148
-		catch(CredisException $e) {
145
+		} catch(CredisException $e) {
149 146
 			throw new Resque_RedisException('Error communicating with Redis: ' . $e->getMessage(), 0, $e);
150 147
 		}
151 148
 	}
@@ -240,15 +237,13 @@  discard block
 block discarded – undo
240 237
 				foreach ($args[0] AS $i => $v) {
241 238
 					$args[0][$i] = self::$defaultNamespace . $v;
242 239
 				}
243
-			}
244
-			else {
240
+			} else {
245 241
 				$args[0] = self::$defaultNamespace . $args[0];
246 242
 			}
247 243
 		}
248 244
 		try {
249 245
 			return $this->driver->__call($name, $args);
250
-		}
251
-		catch (CredisException $e) {
246
+		} catch (CredisException $e) {
252 247
 			throw new Resque_RedisException('Error communicating with Redis: ' . $e->getMessage(), 0, $e);
253 248
 		}
254 249
 	}
Please login to merge, or discard this patch.