Skip to content

Commit 43f74fd

Browse files
committed
refactor to remove one if statement in a loop
1 parent 3ecbeb4 commit 43f74fd

File tree

3 files changed

+3
-6
lines changed

3 files changed

+3
-6
lines changed

Diff for: src/Bucketing/Id.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function strToIntHash(string $idToHash): int
2323
$hex = hash(self::HASH_ALGO, $idToHash);
2424
$dec = hexdec($hex);
2525

26-
$x = $dec / self::TOTAL;
27-
return (int) round($x * 100);
26+
$x = (int) round($dec / self::TOTAL * 100);
27+
return $x === 100 ? 99 : $x;
2828
}
2929
}

Diff for: src/Bucketing/Random.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ public function __construct()
1818

1919
public function strToIntHash(string $idToHash): int
2020
{
21-
return $this->randomizer->getInt(0, 100);
21+
return $this->randomizer->getInt(0, 99);
2222
}
2323
}

Diff for: src/Configurations/Config.php

-3
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@ public function pickVariantOutOfHat(string $id): string
3939
if ($hashOrRandomNumber < $variantRange) {
4040
return $variant;
4141
}
42-
if ($hashOrRandomNumber === 100 && $variantRange === 100) {
43-
return $variant;
44-
}
4542
}
4643

4744
return '';

0 commit comments

Comments
 (0)