Code Duplication    Length = 15-15 lines in 2 locations

src/library/sodium_compat/src/Compat.php 2 locations

@@ 2147-2161 (lines=15) @@
2144
     * @return string
2145
     * @throws TypeError
2146
     */
2147
    public static function randombytes_buf($numBytes)
2148
    {
2149
        /* Type checks: */
2150
        if (!is_int($numBytes)) {
2151
            if (is_numeric($numBytes)) {
2152
                $numBytes = (int)$numBytes;
2153
            } else {
2154
                throw new TypeError('Argument 1 must be an integer, ' . gettype($numBytes) . ' given.');
2155
            }
2156
        }
2157
        if (self::use_fallback('randombytes_buf')) {
2158
            return call_user_func('\\Sodium\\randombytes_buf', $numBytes);
2159
        }
2160
        return random_bytes($numBytes);
2161
    }
2162
2163
    /**
2164
     * Generate an integer between 0 and $range (non-inclusive).
@@ 2170-2184 (lines=15) @@
2167
     * @return int
2168
     * @throws TypeError
2169
     */
2170
    public static function randombytes_uniform($range)
2171
    {
2172
        /* Type checks: */
2173
        if (!is_int($range)) {
2174
            if (is_numeric($range)) {
2175
                $range = (int)$range;
2176
            } else {
2177
                throw new TypeError('Argument 1 must be an integer, ' . gettype($range) . ' given.');
2178
            }
2179
        }
2180
        if (self::use_fallback('randombytes_uniform')) {
2181
            return (int) call_user_func('\\Sodium\\randombytes_uniform', $range);
2182
        }
2183
        return random_int(0, $range - 1);
2184
    }
2185
2186
    /**
2187
     * Generate a random 16-bit integer.