Skip to content

Commit c4bfe12

Browse files
committed
Throw exception if file does not exist or is not a file
1 parent 2b34020 commit c4bfe12

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/Comment.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,18 @@ public static function parse(string $json, bool $assoc = false, int $depth = 512
204204

205205
public static function parseFromFile(string $file, bool $assoc = false, int $depth = 512, int $options = 0)
206206
{
207+
if(!file_exists($file))
208+
{
209+
throw new \RuntimeException(sprintf("File %s does not exist", $file));
210+
}
211+
212+
213+
if(!is_file($file))
214+
{
215+
throw new \RuntimeException(sprintf("%s is not a file", $file));
216+
}
217+
218+
207219
$json = \file_get_contents($file);
208220

209221
return static::parse(\trim($json), $assoc, $depth, $options);

0 commit comments

Comments
 (0)