Skip to content

Commit

Permalink
Add file existence check in FileGetContents class
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
koriym committed Jun 13, 2024
1 parent 8252364 commit 438538e
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/FileGetContents.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Ray\Query\Exception\SqlFileNotReadableException;

use function file_exists;
use function file_get_contents;

final class FileGetContents implements FileGetContentsInterface
Expand All @@ -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
Expand Down

0 comments on commit 438538e

Please sign in to comment.