X-Git-Url: http://aleph1.co.uk/gitweb/?a=blobdiff_plain;f=vendor%2Fparagonie%2Frandom_compat%2Flib%2Frandom_int.php;h=ff80dfa438ac62bb6e3d4e1558221ffc19a4c089;hb=4e1bfbf98b844da83b18aca92ef00f11a4735806;hp=b2ea02d17c5f820ecde415875a16904d5c8007c2;hpb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;p=yaffs-website diff --git a/vendor/paragonie/random_compat/lib/random_int.php b/vendor/paragonie/random_compat/lib/random_int.php index b2ea02d17..ff80dfa43 100644 --- a/vendor/paragonie/random_compat/lib/random_int.php +++ b/vendor/paragonie/random_compat/lib/random_int.php @@ -7,7 +7,7 @@ if (!is_callable('random_int')) { * * The MIT License (MIT) * - * Copyright (c) 2015 - 2017 Paragon Initiative Enterprises + * Copyright (c) 2015 - 2018 Paragon Initiative Enterprises * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -51,6 +51,7 @@ if (!is_callable('random_int')) { */ try { + /** @var int $min */ $min = RandomCompat_intval($min); } catch (TypeError $ex) { throw new TypeError( @@ -59,6 +60,7 @@ if (!is_callable('random_int')) { } try { + /** @var int $max */ $max = RandomCompat_intval($max); } catch (TypeError $ex) { throw new TypeError( @@ -78,7 +80,7 @@ if (!is_callable('random_int')) { } if ($max === $min) { - return $min; + return (int) $min; } /** @@ -90,11 +92,18 @@ if (!is_callable('random_int')) { * so we can minimize the number of discards */ $attempts = $bits = $bytes = $mask = $valueShift = 0; + /** @var int $attempts */ + /** @var int $bits */ + /** @var int $bytes */ + /** @var int $mask */ + /** @var int $valueShift */ /** * At this point, $range is a positive number greater than 0. It might * overflow, however, if $max - $min > PHP_INT_MAX. PHP will cast it to * a float and we will lose some precision. + * + * @var int|float $range */ $range = $max - $min; @@ -115,6 +124,7 @@ if (!is_callable('random_int')) { * @ref http://3v4l.org/XX9r5 (64-bit) */ $bytes = PHP_INT_SIZE; + /** @var int $mask */ $mask = ~0; } else { @@ -129,16 +139,19 @@ if (!is_callable('random_int')) { } ++$bits; $range >>= 1; + /** @var int $mask */ $mask = $mask << 1 | 1; } $valueShift = $min; } + /** @var int $val */ $val = 0; /** * Now that we have our parameters set up, let's begin generating * random integers until one falls between $min and $max */ + /** @psalm-suppress RedundantCondition */ do { /** * The rejection probability is at most 0.5, so this corresponds @@ -169,6 +182,7 @@ if (!is_callable('random_int')) { for ($i = 0; $i < $bytes; ++$i) { $val |= ord($randomByteString[$i]) << ($i * 8); } + /** @var int $val */ /** * Apply mask @@ -185,6 +199,6 @@ if (!is_callable('random_int')) { */ } while (!is_int($val) || $val > $max || $val < $min); - return (int)$val; + return (int) $val; } }