From 438538e5f64eb525bc8c32fb07b8b8abeb93f6a0 Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Thu, 13 Jun 2024 09:55:34 +0900 Subject: [PATCH] Add file existence check in FileGetContents class A check for file existence has been added to the FileGetContents class. Now, before file content is retrieved, the system will check whether the file exists. This reduces the likelihood of encountering a SqlFileNotReadableException. --- src/FileGetContents.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/FileGetContents.php b/src/FileGetContents.php index 24920ec..49fc1e0 100644 --- a/src/FileGetContents.php +++ b/src/FileGetContents.php @@ -6,6 +6,7 @@ use Ray\Query\Exception\SqlFileNotReadableException; +use function file_exists; use function file_get_contents; final class FileGetContents implements FileGetContentsInterface @@ -15,6 +16,10 @@ final class FileGetContents implements FileGetContentsInterface */ public function __invoke(string $filePath): string { + if (! file_exists($filePath)) { + throw new SqlFileNotReadableException($filePath); + } + $content = file_get_contents($filePath); if ($content === false) { // @codeCoverageIgnoreStart