diff --git a/src/Psl/Filesystem/canonicalize.php b/src/Psl/Filesystem/canonicalize.php index ab3404f0..3ee95358 100644 --- a/src/Psl/Filesystem/canonicalize.php +++ b/src/Psl/Filesystem/canonicalize.php @@ -14,5 +14,7 @@ */ function canonicalize(string $path): ?string { - return realpath($path) ?: null; + $path = realpath($path); + + return false !== $path && '' !== $path ? $path : null; } diff --git a/src/Psl/Str/detect_encoding.php b/src/Psl/Str/detect_encoding.php index 05c44f3d..074885df 100644 --- a/src/Psl/Str/detect_encoding.php +++ b/src/Psl/Str/detect_encoding.php @@ -25,7 +25,10 @@ function detect_encoding(string $string, ?array $encoding_list = null): ?Encodin ); } - $encoding = mb_detect_encoding($string, $encoding_list, true) ?: null; + $encoding = mb_detect_encoding($string, $encoding_list, true); + if ($encoding === false) { + return null; + } - return null === $encoding ? $encoding : Encoding::from($encoding); + return Encoding::from($encoding); }