Skip to content

Commit 213f28b

Browse files
pprkutdanhunsaker
authored andcommitted
Fix simple codestyle issues (#53)
1 parent 2e73a35 commit 213f28b

21 files changed

+349
-359
lines changed

lib/Resque.php

Lines changed: 61 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* Base Resque class.
45
*
@@ -10,7 +11,7 @@ class Resque
1011
{
1112
const VERSION = '1.2';
1213

13-
const DEFAULT_INTERVAL = 5;
14+
const DEFAULT_INTERVAL = 5;
1415

1516
/**
1617
* @var Resque_Redis Instance of Resque_Redis that talks to redis.
@@ -28,9 +29,9 @@ class Resque
2829
*/
2930
protected static $redisDatabase = 0;
3031

31-
/**
32-
* @var string auth of Redis database
33-
*/
32+
/**
33+
* @var string auth of Redis database
34+
*/
3435
protected static $auth;
3536

3637
/**
@@ -42,7 +43,7 @@ class Resque
4243
* and returns a Resque_Redis instance, or
4344
* a nested array of servers with host/port pairs.
4445
* @param int $database
45-
* @param string $auth
46+
* @param string $auth
4647
*/
4748
public static function setBackend($server, $database = 0, $auth = null)
4849
{
@@ -70,8 +71,8 @@ public static function redis()
7071
}
7172

7273
if (!empty(self::$auth)) {
73-
self::$redis->auth(self::$auth);
74-
}
74+
self::$redis->auth(self::$auth);
75+
}
7576

7677
return self::$redis;
7778
}
@@ -87,7 +88,7 @@ public static function redis()
8788
*/
8889
public static function fork()
8990
{
90-
if(!function_exists('pcntl_fork')) {
91+
if (!function_exists('pcntl_fork')) {
9192
return false;
9293
}
9394

@@ -96,7 +97,7 @@ public static function fork()
9697
self::$redis = null;
9798

9899
$pid = pcntl_fork();
99-
if($pid === -1) {
100+
if ($pid === -1) {
100101
throw new RuntimeException('Unable to fork child worker.');
101102
}
102103

@@ -133,9 +134,9 @@ public static function push($queue, $item)
133134
*/
134135
public static function pop($queue)
135136
{
136-
$item = self::redis()->lpop('queue:' . $queue);
137+
$item = self::redis()->lpop('queue:' . $queue);
137138

138-
if(!$item) {
139+
if (!$item) {
139140
return;
140141
}
141142

@@ -149,13 +150,13 @@ public static function pop($queue)
149150
* @param array $items
150151
* @return integer number of deleted items
151152
*/
152-
public static function dequeue($queue, $items = Array())
153+
public static function dequeue($queue, $items = array())
153154
{
154-
if(count($items) > 0) {
155+
if (count($items) > 0) {
155156
return self::removeItems($queue, $items);
156-
} else {
157+
} else {
157158
return self::removeList($queue);
158-
}
159+
}
159160
}
160161

161162
/**
@@ -166,9 +167,9 @@ public static function dequeue($queue, $items = Array())
166167
*/
167168
public static function removeQueue($queue)
168169
{
169-
$num = self::removeList($queue);
170-
self::redis()->srem('queues', $queue);
171-
return $num;
170+
$num = self::removeList($queue);
171+
self::redis()->srem('queues', $queue);
172+
return $num;
172173
}
173174

174175
/**
@@ -181,28 +182,28 @@ public static function removeQueue($queue)
181182
*/
182183
public static function blpop(array $queues, $timeout)
183184
{
184-
$list = array();
185-
foreach($queues AS $queue) {
186-
$list[] = 'queue:' . $queue;
187-
}
185+
$list = array();
186+
foreach ($queues as $queue) {
187+
$list[] = 'queue:' . $queue;
188+
}
188189

189-
$item = self::redis()->blpop($list, (int)$timeout);
190+
$item = self::redis()->blpop($list, (int)$timeout);
190191

191-
if(!$item) {
192-
return;
193-
}
192+
if (!$item) {
193+
return;
194+
}
194195

195-
/**
196-
* Normally the Resque_Redis class returns queue names without the prefix
197-
* But the blpop is a bit different. It returns the name as prefix:queue:name
198-
* So we need to strip off the prefix:queue: part
199-
*/
200-
$queue = substr($item[0], strlen(self::redis()->getPrefix() . 'queue:'));
196+
/**
197+
* Normally the Resque_Redis class returns queue names without the prefix
198+
* But the blpop is a bit different. It returns the name as prefix:queue:name
199+
* So we need to strip off the prefix:queue: part
200+
*/
201+
$queue = substr($item[0], strlen(self::redis()->getPrefix() . 'queue:'));
201202

202-
return array(
203+
return array(
203204
'queue' => $queue,
204205
'payload' => json_decode($item[1], true)
205-
);
206+
);
206207
}
207208

208209
/**
@@ -239,8 +240,7 @@ public static function enqueue($queue, $class, $args = null, $trackStatus = fals
239240
);
240241
try {
241242
Resque_Event::trigger('beforeEnqueue', $hookParams);
242-
}
243-
catch(Resque_Job_DontCreate $e) {
243+
} catch (Resque_Job_DontCreate $e) {
244244
return false;
245245
}
246246

@@ -269,7 +269,7 @@ public static function reserve($queue)
269269
public static function queues()
270270
{
271271
$queues = self::redis()->smembers('queues');
272-
if(!is_array($queues)) {
272+
if (!is_array($queues)) {
273273
$queues = array();
274274
}
275275
return $queues;
@@ -283,7 +283,7 @@ public static function queues()
283283
public static function items($queue, $start = 0, $stop = -1)
284284
{
285285
$list = self::redis()->lrange('queue:' . $queue, $start, $stop);
286-
if(!is_array($list)) {
286+
if (!is_array($list)) {
287287
$list = array();
288288
}
289289
return $list;
@@ -301,20 +301,20 @@ public static function items($queue, $start = 0, $stop = -1)
301301
* @param array $items
302302
* @return integer number of deleted items
303303
*/
304-
private static function removeItems($queue, $items = Array())
304+
private static function removeItems($queue, $items = array())
305305
{
306306
$counter = 0;
307-
$originalQueue = 'queue:'. $queue;
308-
$tempQueue = $originalQueue. ':temp:'. time();
309-
$requeueQueue = $tempQueue. ':requeue';
307+
$originalQueue = 'queue:' . $queue;
308+
$tempQueue = $originalQueue . ':temp:' . time();
309+
$requeueQueue = $tempQueue . ':requeue';
310310

311311
// move each item from original queue to temp queue and process it
312312
$finished = false;
313313
while (!$finished) {
314314
$string = self::redis()->rpoplpush($originalQueue, self::redis()->getPrefix() . $tempQueue);
315315

316316
if (!empty($string)) {
317-
if(self::matchItem($string, $items)) {
317+
if (self::matchItem($string, $items)) {
318318
self::redis()->rpop($tempQueue);
319319
$counter++;
320320
} else {
@@ -328,9 +328,9 @@ private static function removeItems($queue, $items = Array())
328328
// move back from temp queue to original queue
329329
$finished = false;
330330
while (!$finished) {
331-
$string = self::redis()->rpoplpush($requeueQueue, self::redis()->getPrefix() .$originalQueue);
331+
$string = self::redis()->rpoplpush($requeueQueue, self::redis()->getPrefix() . $originalQueue);
332332
if (empty($string)) {
333-
$finished = true;
333+
$finished = true;
334334
}
335335
}
336336

@@ -353,29 +353,31 @@ private static function removeItems($queue, $items = Array())
353353
*/
354354
private static function matchItem($string, $items)
355355
{
356-
$decoded = json_decode($string, true);
356+
$decoded = json_decode($string, true);
357357

358-
foreach($items as $key => $val) {
358+
foreach ($items as $key => $val) {
359359
# class name only ex: item[0] = ['class']
360360
if (is_numeric($key)) {
361-
if($decoded['class'] == $val) {
361+
if ($decoded['class'] == $val) {
362362
return true;
363-
}
363+
}
364364
# class name with args , example: item[0] = ['class' => {'foo' => 1, 'bar' => 2}]
365365
} elseif (is_array($val)) {
366-
$decodedArgs = (array)$decoded['args'][0];
367-
if ($decoded['class'] == $key &&
368-
count($decodedArgs) > 0 && count(array_diff($decodedArgs, $val)) == 0) {
366+
$decodedArgs = (array)$decoded['args'][0];
367+
if (
368+
$decoded['class'] == $key &&
369+
count($decodedArgs) > 0 && count(array_diff($decodedArgs, $val)) == 0
370+
) {
369371
return true;
370372
}
371373
# class name with ID, example: item[0] = ['class' => 'id']
372374
} else {
373-
if ($decoded['class'] == $key && $decoded['id'] == $val) {
375+
if ($decoded['class'] == $key && $decoded['id'] == $val) {
374376
return true;
375-
}
377+
}
376378
}
377-
}
378-
return false;
379+
}
380+
return false;
379381
}
380382

381383
/**
@@ -388,9 +390,9 @@ private static function matchItem($string, $items)
388390
*/
389391
private static function removeList($queue)
390392
{
391-
$counter = self::size($queue);
392-
$result = self::redis()->del('queue:' . $queue);
393-
return ($result == 1) ? $counter : 0;
393+
$counter = self::size($queue);
394+
$result = self::redis()->del('queue:' . $queue);
395+
return ($result == 1) ? $counter : 0;
394396
}
395397

396398
/*

lib/Resque/Event.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* Resque event/plugin system class
45
*
@@ -29,17 +30,17 @@ public static function trigger($event, $data = null)
2930
if (empty(self::$events[$event])) {
3031
return true;
3132
}
32-
33+
3334
foreach (self::$events[$event] as $callback) {
3435
if (!is_callable($callback)) {
3536
continue;
3637
}
3738
call_user_func_array($callback, $data);
3839
}
39-
40+
4041
return true;
4142
}
42-
43+
4344
/**
4445
* Listen in on a given event to have a specified callback fired.
4546
*
@@ -52,11 +53,11 @@ public static function listen($event, $callback)
5253
if (!isset(self::$events[$event])) {
5354
self::$events[$event] = array();
5455
}
55-
56+
5657
self::$events[$event][] = $callback;
5758
return true;
5859
}
59-
60+
6061
/**
6162
* Stop a given callback from listening on a specific event.
6263
*
@@ -69,15 +70,15 @@ public static function stopListening($event, $callback)
6970
if (!isset(self::$events[$event])) {
7071
return true;
7172
}
72-
73+
7374
$key = array_search($callback, self::$events[$event]);
7475
if ($key !== false) {
7576
unset(self::$events[$event][$key]);
7677
}
77-
78+
7879
return true;
7980
}
80-
81+
8182
/**
8283
* Call all registered listeners.
8384
*/

lib/Resque/Exception.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* Resque exception.
45
*

lib/Resque/Failure.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public static function createFromError($payload, Error $exception, Resque_Worker
4949
*/
5050
public static function getBackend()
5151
{
52-
if(self::$backend === null) {
52+
if (self::$backend === null) {
5353
self::$backend = 'Resque_Failure_Redis';
5454
}
5555

@@ -67,4 +67,4 @@ public static function setBackend($backend)
6767
{
6868
self::$backend = $backend;
6969
}
70-
}
70+
}

lib/Resque/Failure/Interface.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* Interface that all failure backends should implement.
45
*

lib/Resque/Failure/Redis.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* Redis backend for storing failed Resque jobs.
45
*
@@ -19,7 +20,7 @@ class Resque_Failure_Redis implements Resque_Failure_Interface
1920
*/
2021
public function __construct($payload, $exception, $worker, $queue)
2122
{
22-
$data = new stdClass;
23+
$data = new stdClass();
2324
$data->failed_at = date('c');
2425
$data->payload = $payload;
2526
$data->exception = get_class($exception);

0 commit comments

Comments
 (0)