From 3846a5361a525ce0a3defa8380afc661f7e88c3a Mon Sep 17 00:00:00 2001 From: Sergey Panteleev Date: Tue, 26 Sep 2023 20:12:16 +0300 Subject: [PATCH] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Tim Düsterhus --- releases/8.3/release.inc | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/releases/8.3/release.inc b/releases/8.3/release.inc index 976ae3c9ab..7b68076ab0 100644 --- a/releases/8.3/release.inc +++ b/releases/8.3/release.inc @@ -156,7 +156,10 @@ function getBytesFromString(string $string, int $length) { $randomDomain = sprintf( "%s.example.com", - getBytesFromString('abcdefghijklmnopqrstuvwxyz0123456789', 16), + getBytesFromString( + 'abcdefghijklmnopqrstuvwxyz0123456789', + 16, + ), ); echo $randomDomain; @@ -171,12 +174,16 @@ PHP
getBytesFromString('abcdefghijklmnopqrstuvwxyz0123456789', 16), + $randomizer->getBytesFromString( + 'abcdefghijklmnopqrstuvwxyz0123456789', + 16, + ), ); echo $randomDomain; @@ -203,7 +210,8 @@ function getFloat(float $min, float $max) { // This algorithm is biased for specific inputs and may // return values outside the given range. This is impossible // to work around in userland. - return (random_int(0, PHP_INT_MAX) / PHP_INT_MAX) * ($max - $min) + $min; + $offset = random_int(0, PHP_INT_MAX) / PHP_INT_MAX; + return $offset * ($max - $min) + $min; } $temperature = getFloat(-89.2, 56.7); @@ -225,10 +233,15 @@ PHP <<<'PHP' $randomizer = new \Random\Randomizer(); -$temperature = $randomizer->getFloat(-89.2, 56.7, \Random\IntervalBoundary::ClosedClosed); +$temperature = $randomizer->getFloat( + -89.2, + 56.7, + \Random\IntervalBoundary::ClosedClosed, +); $chanceForTrue = 0.1; -// Randomizer::nextFloat() is equivalent to Randomizer::getFloat(0, 1, \Random\IntervalBoundary::ClosedOpen). +// Randomizer::nextFloat() is equivalent to +// Randomizer::getFloat(0, 1, \Random\IntervalBoundary::ClosedOpen). // The upper bound, i.e. 1, will not be returned. $myBoolean = $randomizer->nextFloat(); < $chanceForTrue; PHP