diff --git a/psalm.xml b/psalm.xml
index c6b2562..2bb7a06 100644
--- a/psalm.xml
+++ b/psalm.xml
@@ -13,4 +13,18 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Builder.php b/src/Builder.php
index f4a3213..2bc5701 100644
--- a/src/Builder.php
+++ b/src/Builder.php
@@ -1072,7 +1072,13 @@ private function round(float $number): int
*/
private function random_float(float|int $min, float|int $max): float
{
- # See https://www.php.net/manual/en/function.mt-rand.php#75793
- return ($min + lcg_value() * (abs($max - $min)));
+ if (class_exists(\Random\Randomizer::class) && method_exists(\Random\Randomizer::class, "getFloat")) {
+ # getFloat() was introduced in PHP 8.3
+ $randomizer = new \Random\Randomizer();
+ return $randomizer->getFloat($min, $max);
+ } else {
+ # See https://www.php.net/manual/en/function.mt-rand.php#75793
+ return ($min + lcg_value() * (abs($max - $min)));
+ }
}
}
diff --git a/src/Helpers/Dir.php b/src/Helpers/Dir.php
index 4b10245..ec7904b 100644
--- a/src/Helpers/Dir.php
+++ b/src/Helpers/Dir.php
@@ -49,11 +49,11 @@ class Dir
* Get all files
*
* @param string $dir
- * @param array $ignore
+ * @param array|null $ignore
* @param bool $absolute
* @return array
*/
- public static function files(string $dir, array $ignore = null, bool $absolute = false): array
+ public static function files(string $dir, ?array $ignore = null, bool $absolute = false): array
{
$result = array_values(array_filter(static::read($dir, $ignore, true), 'is_file'));
@@ -108,11 +108,11 @@ public static function make(string $dir, bool $recursive = true): bool
* It skips unwanted invisible stuff.
*
* @param string $dir The path of directory
- * @param array $ignore Optional array with filenames, which should be ignored
+ * @param array|null $ignore Optional array with filenames, which should be ignored
* @param bool $absolute If true, the full path for each item will be returned
* @return array An array of filenames
*/
- public static function read(string $dir, array $ignore = null, bool $absolute = false): array
+ public static function read(string $dir, ?array $ignore = null, bool $absolute = false): array
{
if (is_dir($dir) === false) {
return [];
diff --git a/src/Helpers/F.php b/src/Helpers/F.php
index 986ea82..4bde592 100644
--- a/src/Helpers/F.php
+++ b/src/Helpers/F.php
@@ -45,10 +45,10 @@ public static function dirname(string $file): string
* Checks if the file exists on disk
*
* @param string $file
- * @param string $in
+ * @param string|null $in
* @return bool
*/
- public static function exists(string $file, string $in = null): bool
+ public static function exists(string $file, ?string $in = null): bool
{
try {
static::realpath($file, $in);
@@ -62,11 +62,11 @@ public static function exists(string $file, string $in = null): bool
/**
* Gets the extension of a file
*
- * @param string $file The filename or path
- * @param string $extension Set an optional extension to overwrite the current one
+ * @param string|null $file The filename or path
+ * @param string|null $extension Set an optional extension to overwrite the current one
* @return string
*/
- public static function extension(string $file = null, string $extension = null): string
+ public static function extension(?string $file = null, ?string $extension = null): string
{
// overwrite the current extension
if ($extension !== null) {
@@ -130,10 +130,10 @@ public static function name(string $name): string
* Returns the absolute path to the file if the file can be found.
*
* @param string $file
- * @param string $in
+ * @param string|null $in
* @return string|null
*/
- public static function realpath(string $file, string $in = null)
+ public static function realpath(string $file, ?string $in = null)
{
$realpath = realpath($file);
diff --git a/src/Helpers/Mime.php b/src/Helpers/Mime.php
index 5f97de9..36b3ef9 100644
--- a/src/Helpers/Mime.php
+++ b/src/Helpers/Mime.php
@@ -2,9 +2,6 @@
namespace SimpleCaptcha\Helpers;
-use SimpleCaptcha\Helpers\F;
-
-
/**
* The `Mime` class provides method
* for MIME type detection or guessing
@@ -168,10 +165,10 @@ public static function fromMimeContentType(string $file)
* Returns the MIME type of a file
*
* @param string $file
- * @param string $extension
+ * @param string|null $extension
* @return string|false
*/
- public static function type(string $file, string $extension = null)
+ public static function type(string $file, ?string $extension = null)
{
// use the standard finfo extension
$mime = static::fromFileInfo($file);
diff --git a/src/Helpers/Str.php b/src/Helpers/Str.php
index 32baf19..8f163f4 100644
--- a/src/Helpers/Str.php
+++ b/src/Helpers/Str.php
@@ -24,7 +24,7 @@ class Str
* @param bool $caseInsensitive
* @return bool
*/
- public static function contains(string $string = null, string $needle, bool $caseInsensitive = false): bool
+ public static function contains(string $string, string $needle, bool $caseInsensitive = false): bool
{
if ($needle === '') {
return true;
@@ -38,10 +38,10 @@ public static function contains(string $string = null, string $needle, bool $cas
/**
* A UTF-8 safe version of strlen()
*
- * @param string $string
+ * @param string|null $string
* @return int
*/
- public static function length(string $string = null): int
+ public static function length(?string $string = null): int
{
return mb_strlen($string ?? '', 'UTF-8');
}
@@ -50,10 +50,10 @@ public static function length(string $string = null): int
/**
* A UTF-8 safe version of strtolower()
*
- * @param string $string
+ * @param string|null $string
* @return string
*/
- public static function lower(string $string = null): string
+ public static function lower(?string $string = null): string
{
return mb_strtolower($string ?? '', 'UTF-8');
}
@@ -81,7 +81,7 @@ public static function ltrim(string $string, string $trim = ' '): string
* @param bool $caseInsensitive
* @return int|bool
*/
- public static function position(string $string = null, string $needle, bool $caseInsensitive = false)
+ public static function position(string $string, string $needle, bool $caseInsensitive = false)
{
if ($caseInsensitive === true) {
$string = static::lower($string);
@@ -113,7 +113,7 @@ public static function rtrim(string $string, string $trim = ' '): string
* @param bool $caseInsensitive
* @return bool
*/
- public static function startsWith(string $string = null, string $needle, bool $caseInsensitive = false): bool
+ public static function startsWith(string $string, string $needle, bool $caseInsensitive = false): bool
{
if ($needle === '') {
return true;
@@ -131,9 +131,9 @@ public static function startsWith(string $string = null, string $needle, bool $c
* @param int $length
* @return string
*/
- public static function substr(string $string = null, int $start = 0, int $length = null): string
+ public static function substr(string $string, int $start, int $length): string
{
- return mb_substr($string ?? '', $start, $length, 'UTF-8');
+ return mb_substr($string, $start, $length, 'UTF-8');
}