From dafe99b33d9e2b18be66585a2dab3939a0616e3f Mon Sep 17 00:00:00 2001 From: Toon Verwerft Date: Thu, 18 Jan 2024 15:07:35 +0100 Subject: [PATCH] Fix psalm 5.20 issues --- src/Psl/Filesystem/canonicalize.php | 4 +++- src/Psl/Str/detect_encoding.php | 7 +++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Psl/Filesystem/canonicalize.php b/src/Psl/Filesystem/canonicalize.php index ab3404f0..7122f0d5 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); }