Skip to content

Commit

Permalink
refactor to remove one if statement in a loop
Browse files Browse the repository at this point in the history
  • Loading branch information
PabloJoan committed Nov 29, 2023
1 parent 3ecbeb4 commit 43f74fd
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/Bucketing/Id.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function strToIntHash(string $idToHash): int
$hex = hash(self::HASH_ALGO, $idToHash);
$dec = hexdec($hex);

$x = $dec / self::TOTAL;
return (int) round($x * 100);
$x = (int) round($dec / self::TOTAL * 100);
return $x === 100 ? 99 : $x;
}
}
2 changes: 1 addition & 1 deletion src/Bucketing/Random.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ public function __construct()

public function strToIntHash(string $idToHash): int
{
return $this->randomizer->getInt(0, 100);
return $this->randomizer->getInt(0, 99);
}
}
3 changes: 0 additions & 3 deletions src/Configurations/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ public function pickVariantOutOfHat(string $id): string
if ($hashOrRandomNumber < $variantRange) {
return $variant;
}
if ($hashOrRandomNumber === 100 && $variantRange === 100) {
return $variant;
}
}

return '';
Expand Down

0 comments on commit 43f74fd

Please sign in to comment.