summaryrefslogtreecommitdiff
path: root/vendor/paragonie/random_compat/lib/cast_to_int.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/paragonie/random_compat/lib/cast_to_int.php')
-rw-r--r--vendor/paragonie/random_compat/lib/cast_to_int.php26
1 files changed, 15 insertions, 11 deletions
diff --git a/vendor/paragonie/random_compat/lib/cast_to_int.php b/vendor/paragonie/random_compat/lib/cast_to_int.php
index f441c5d9..9a4fab99 100644
--- a/vendor/paragonie/random_compat/lib/cast_to_int.php
+++ b/vendor/paragonie/random_compat/lib/cast_to_int.php
@@ -5,7 +5,7 @@
*
* The MIT License (MIT)
*
- * Copyright (c) 2015 Paragon Initiative Enterprises
+ * Copyright (c) 2015 - 2017 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
@@ -26,7 +26,7 @@
* SOFTWARE.
*/
-if (!function_exists('RandomCompat_intval')) {
+if (!is_callable('RandomCompat_intval')) {
/**
* Cast to an integer if we can, safely.
@@ -38,15 +38,18 @@ if (!function_exists('RandomCompat_intval')) {
* through.
*
* @param int|float $number The number we want to convert to an int
- * @param boolean $fail_open Set to true to not throw an exception
+ * @param bool $fail_open Set to true to not throw an exception
*
- * @return int (or float if $fail_open)
+ * @return float|int
+ * @psalm-suppress InvalidReturnType
*
* @throws TypeError
*/
function RandomCompat_intval($number, $fail_open = false)
{
- if (is_numeric($number)) {
+ if (is_int($number) || is_float($number)) {
+ $number += 0;
+ } elseif (is_numeric($number)) {
$number += 0;
}
@@ -60,12 +63,13 @@ if (!function_exists('RandomCompat_intval')) {
$number = (int) $number;
}
- if (is_int($number) || $fail_open) {
- return $number;
+ if (is_int($number)) {
+ return (int) $number;
+ } elseif (!$fail_open) {
+ throw new TypeError(
+ 'Expected an integer.'
+ );
}
-
- throw new TypeError(
- 'Expected an integer.'
- );
+ return $number;
}
}