Skip to content

Commit 0ee6aeb

Browse files
committed
Merge pull request #34 from gaillard/master
Use php 5.4 array syntax.
2 parents a138db0 + c910aa3 commit 0ee6aeb

3 files changed

Lines changed: 142 additions & 151 deletions

File tree

build.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@
1111
require 'vendor/autoload.php';
1212

1313
$phpcsCLI = new PHP_CodeSniffer_CLI();
14-
$phpcsArguments = array(
15-
'standard' => array(__DIR__ . '/vendor/dominionenterprises/dws-coding-standard/DWS'),
16-
'files' => array('src', 'tests', 'build.php'),
14+
$phpcsArguments = [
15+
'standard' => [__DIR__ . '/vendor/dominionenterprises/dws-coding-standard/DWS'],
16+
'files' => ['src', 'tests', 'build.php'],
1717
'warningSeverity' => 0,
18-
);
18+
];
1919
$phpcsViolations = $phpcsCLI->process($phpcsArguments);
2020
if ($phpcsViolations > 0) {
2121
exit(1);
2222
}
2323

2424
$phpunitConfiguration = PHPUnit_Util_Configuration::getInstance(__DIR__ . '/phpunit.xml');
25-
$phpunitArguments = array('coverageHtml' => __DIR__ . '/coverage', 'configuration' => $phpunitConfiguration);
25+
$phpunitArguments = ['coverageHtml' => __DIR__ . '/coverage', 'configuration' => $phpunitConfiguration];
2626
$testRunner = new PHPUnit_TextUI_TestRunner();
2727
$result = $testRunner->doRun($phpunitConfiguration->getTestSuiteConfiguration(), $phpunitArguments);
2828
if (!$result->wasSuccessful()) {

src/Queue.php

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ public function __construct($url, $db, $collection)
6161
* @throws \InvalidArgumentException value of $beforeSort or $afterSort is not 1 or -1 for ascending and descending
6262
* @throws \InvalidArgumentException key in $beforeSort or $afterSort was not a string
6363
*/
64-
public function ensureGetIndex(array $beforeSort = array(), array $afterSort = array())
64+
public function ensureGetIndex(array $beforeSort = [], array $afterSort = [])
6565
{
6666
//using general rule: equality, sort, range or more equality tests in that order for index
67-
$completeFields = array('running' => 1);
67+
$completeFields = ['running' => 1];
6868

6969
foreach ($beforeSort as $key => $value) {
7070
if (!is_string($key)) {
@@ -99,7 +99,7 @@ public function ensureGetIndex(array $beforeSort = array(), array $afterSort = a
9999
$this->_ensureIndex($completeFields);
100100

101101
//for the stuck messages query in get()
102-
$this->_ensureIndex(array('running' => 1, 'resetTimestamp' => 1));
102+
$this->_ensureIndex(['running' => 1, 'resetTimestamp' => 1]);
103103
}
104104

105105
/**
@@ -121,7 +121,7 @@ public function ensureCountIndex(array $fields, $includeRunning)
121121
throw new \InvalidArgumentException('$includeRunning was not a boolean');
122122
}
123123

124-
$completeFields = array();
124+
$completeFields = [];
125125

126126
if ($includeRunning) {
127127
$completeFields['running'] = 1;
@@ -176,12 +176,12 @@ public function get(array $query, $runningResetDuration, $waitDurationInMillis =
176176

177177
//reset stuck messages
178178
$this->_collection->update(
179-
array('running' => true, 'resetTimestamp' => array('$lte' => new \MongoDate())),
180-
array('$set' => array('running' => false)),
181-
array('multiple' => true)
179+
['running' => true, 'resetTimestamp' => ['$lte' => new \MongoDate()]],
180+
['$set' => ['running' => false]],
181+
['multiple' => true]
182182
);
183183

184-
$completeQuery = array('running' => false);
184+
$completeQuery = ['running' => false];
185185
foreach ($query as $key => $value) {
186186
if (!is_string($key)) {
187187
throw new \InvalidArgumentException('key in $query was not a string');
@@ -190,17 +190,17 @@ public function get(array $query, $runningResetDuration, $waitDurationInMillis =
190190
$completeQuery["payload.{$key}"] = $value;
191191
}
192192

193-
$completeQuery['earliestGet'] = array('$lte' => new \MongoDate());
193+
$completeQuery['earliestGet'] = ['$lte' => new \MongoDate()];
194194

195195
$resetTimestamp = time() + $runningResetDuration;
196196
//ints overflow to floats
197197
if (!is_int($resetTimestamp)) {
198198
$resetTimestamp = $runningResetDuration > 0 ? self::MONGO_INT32_MAX : 0;
199199
}
200200

201-
$update = array('$set' => array('resetTimestamp' => new \MongoDate($resetTimestamp), 'running' => true));
202-
$fields = array('payload' => 1);
203-
$options = array('sort' => array('priority' => 1, 'created' => 1));
201+
$update = ['$set' => ['resetTimestamp' => new \MongoDate($resetTimestamp), 'running' => true]];
202+
$fields = ['payload' => 1];
203+
$options = ['sort' => ['priority' => 1, 'created' => 1]];
204204

205205
//ints overflow to floats, should be fine
206206
$end = microtime(true) + ($waitDurationInMillis / 1000.0);
@@ -218,7 +218,7 @@ public function get(array $query, $runningResetDuration, $waitDurationInMillis =
218218
//checking if _id exist because findAndModify doesnt seem to return null when it can't match the query on older mongo extension
219219
if ($message !== null && array_key_exists('_id', $message)) {
220220
//id on left of union operator so a possible id in payload doesnt wipe it out the generated one
221-
return array('id' => $message['_id']) + $message['payload'];
221+
return ['id' => $message['_id']] + $message['payload'];
222222
}
223223

224224
if (microtime(true) >= $end) {
@@ -251,7 +251,7 @@ public function count(array $query, $running = null)
251251
throw new \InvalidArgumentException('$running was not null and not a bool');
252252
}
253253

254-
$totalQuery = array();
254+
$totalQuery = [];
255255

256256
if ($running !== null) {
257257
$totalQuery['running'] = $running;
@@ -288,7 +288,7 @@ public function ack(array $message)
288288
throw new \InvalidArgumentException('$message does not have a field "id" that is a MongoId');
289289
}
290290

291-
$this->_collection->remove(array('_id' => $id));
291+
$this->_collection->remove(['_id' => $id]);
292292
}
293293

294294
/**
@@ -341,19 +341,19 @@ public function ackSend(array $message, array $payload, $earliestGet = 0, $prior
341341
$earliestGet = 0;
342342
}
343343

344-
$toSet = array(
344+
$toSet = [
345345
'payload' => $payload,
346346
'running' => false,
347347
'resetTimestamp' => new \MongoDate(self::MONGO_INT32_MAX),
348348
'earliestGet' => new \MongoDate($earliestGet),
349349
'priority' => $priority,
350-
);
350+
];
351351
if ($newTimestamp) {
352352
$toSet['created'] = new \MongoDate();
353353
}
354354

355355
//using upsert because if no documents found then the doc was removed (SHOULD ONLY HAPPEN BY SOMEONE MANUALLY) so we can just send
356-
$this->_collection->update(array('_id' => $id), array('$set' => $toSet), array('upsert' => true));
356+
$this->_collection->update(['_id' => $id], ['$set' => $toSet], ['upsert' => true]);
357357
}
358358

359359
/**
@@ -412,14 +412,14 @@ public function send(array $payload, $earliestGet = 0, $priority = 0.0)
412412
$earliestGet = 0;
413413
}
414414

415-
$message = array(
415+
$message = [
416416
'payload' => $payload,
417417
'running' => false,
418418
'resetTimestamp' => new \MongoDate(self::MONGO_INT32_MAX),
419419
'earliestGet' => new \MongoDate($earliestGet),
420420
'priority' => $priority,
421421
'created' => new \MongoDate(),
422-
);
422+
];
423423

424424
$this->_collection->insert($message);
425425
}
@@ -451,7 +451,7 @@ private function _ensureIndex(array $index)
451451
//so we use any generated name, and then find the right spec after we have called, and just go with that name.
452452

453453
try {
454-
$this->_collection->ensureIndex($index, array('name' => $name, 'background' => true));
454+
$this->_collection->ensureIndex($index, ['name' => $name, 'background' => true]);
455455
} catch (\MongoException $e) {
456456
//this happens when the name was too long, let continue
457457
}

0 commit comments

Comments
 (0)