Skip to content

Commit 3ff0d05

Browse files
committed
Simplify to just checking if file or not
Update tests for simplified exception
1 parent fab4dd3 commit 3ff0d05

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

src/Comment.php

+1-5
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,8 @@ 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-
throw new \RuntimeException(sprintf('File %s does not exist', $file));
209-
}
210-
211207
if (!is_file($file)) {
212-
throw new \RuntimeException(sprintf('%s is not a file', $file));
208+
throw new \RuntimeException($file . ' does not exist or is not a file');
213209
}
214210

215211
$json = \file_get_contents($file);

tests/CommentTest.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,18 @@ public function testParseFromFile()
7070

7171
public function testParseFromFileThrowsNotExists()
7272
{
73+
$file = 'does-not-exist.json';
74+
7375
$this->expectException(\RuntimeException::class);
74-
$this->expectExceptionMessage('File does-not-exist.json does not exist');
76+
$this->expectExceptionMessage($file . ' does not exist or is not a file');
7577

76-
Comment::parseFromFile('does-not-exist.json', true);
78+
Comment::parseFromFile($file, true);
7779
}
7880

7981
public function testParseFromFileThrowsNotFile()
8082
{
8183
$this->expectException(\RuntimeException::class);
82-
$this->expectExceptionMessage(__DIR__ . ' is not a file');
84+
$this->expectExceptionMessage(__DIR__ . ' does not exist or is not a file');
8385

8486
Comment::parseFromFile(__DIR__, true);
8587
}

0 commit comments

Comments
 (0)