Skip to content

Commit a8d2bfa

Browse files
committed
Use calls to min() and max() instead of if/elseif
When setting $earliestGet use nested calls to min() and max() to reduce the number of decision trees
1 parent 3ece7e8 commit a8d2bfa

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

src/Queue.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -318,11 +318,8 @@ public function ackSend(array $message, array $payload, $earliestGet = 0, $prior
318318
throw new \InvalidArgumentException('$newTimestamp was not a bool');
319319
}
320320

321-
if ($earliestGet > self::MONGO_INT32_MAX) {
322-
$earliestGet = self::MONGO_INT32_MAX;
323-
} elseif ($earliestGet < 0) {
324-
$earliestGet = 0;
325-
}
321+
//Ensure $earliestGet is between 0 and MONGO_INT32_MAX
322+
$earliestGet = min(max(0, $earliestGet), self::MONGO_INT32_MAX);
326323

327324
$toSet = [
328325
'payload' => $payload,
@@ -390,11 +387,8 @@ public function send(array $payload, $earliestGet = 0, $priority = 0.0)
390387
throw new \InvalidArgumentException('$priority was NaN');
391388
}
392389

393-
if ($earliestGet > self::MONGO_INT32_MAX) {
394-
$earliestGet = self::MONGO_INT32_MAX;
395-
} elseif ($earliestGet < 0) {
396-
$earliestGet = 0;
397-
}
390+
//Ensure $earliestGet is between 0 and MONGO_INT32_MAX
391+
$earliestGet = min(max(0, $earliestGet), self::MONGO_INT32_MAX);
398392

399393
$message = [
400394
'payload' => $payload,

0 commit comments

Comments
 (0)