Skip to content

Commit

Permalink
Clamp $expireSecs instead of using nasty if/else logic
Browse files Browse the repository at this point in the history
  • Loading branch information
chadicus committed Mar 16, 2017
1 parent 31fabd2 commit 3bf4e86
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions src/ProcessRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,8 @@ public function add(

// add our process
$expireSecs = time() + $minsBeforeExpire * 60;
if (!is_int($expireSecs)) {
if ($minsBeforeExpire > 0) {
$expireSecs = self::MONGO_INT32_MAX;
} else {
$expireSecs = 0;
}
}
//ensure expireSecs is between 0 and self::MONGO_INT32_MAX
$expireSecs = max(0, min($expireSecs, self::MONGO_INT32_MAX));

$thisHostPids[$thisPid] = $expireSecs;
$replacement['hosts'][$thisHostName] = $thisHostPids;
Expand Down Expand Up @@ -168,13 +163,8 @@ public function remove(string $id)
public function reset(string $id, int $minsBeforeExpire)
{
$expireSecs = time() + $minsBeforeExpire * 60;
if (!is_int($expireSecs)) {
if ($minsBeforeExpire > 0) {
$expireSecs = self::MONGO_INT32_MAX;
} else {
$expireSecs = 0;
}
}
//ensure expireSecs is between 0 and self::MONGO_INT32_MAX
$expireSecs = max(0, min($expireSecs, self::MONGO_INT32_MAX));

$thisHostName = self::_getEncodedHostname();
$thisPid = getmypid();
Expand Down

0 comments on commit 3bf4e86

Please sign in to comment.