Skip to content

Commit 5444952

Browse files
Add messages of Exceptions
1 parent c19b570 commit 5444952

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/Parser.php

+10-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Differ\Parser;
44

5+
use Exception;
56
use Symfony\Component\Yaml\Yaml;
67

78
use function Differ\Formatters\selectFormatter;
@@ -11,24 +12,30 @@ function parse(array $resultDiff, string $format): string
1112
return selectFormatter($resultDiff, $format);
1213
}
1314

15+
/**
16+
* @throws Exception
17+
*/
1418
function parseToJson(string $path): array
1519
{
1620
$content = getFileContent($path);
1721
$offset = strpos($path, '.');
1822

1923
if ($offset === false) {
20-
throw new \Exception("Incorrect path");
24+
throw new Exception("Incorrect path: {$path}");
2125
}
2226

2327
$extension = substr($path, $offset + 1);
2428

2529
return match ($extension) {
2630
'json' => json_decode($content, true),
2731
'yaml' => Yaml::parse($content),
28-
default => throw new \Exception("There is no such extension: {$extension}")
32+
default => throw new Exception("The file format is not supported by the current version of the program: {$extension}")
2933
};
3034
}
3135

36+
/**
37+
* @throws Exception
38+
*/
3239
function getFileContent(string $path): string
3340
{
3441
$dirPath = __DIR__;
@@ -40,7 +47,7 @@ function getFileContent(string $path): string
4047
}
4148

4249
if (!file_exists($fullPath)) {
43-
throw new \Exception("Incorrect path");
50+
throw new Exception("File does not exist: {$path}");
4451
}
4552

4653
return file_get_contents($fullPath);

0 commit comments

Comments
 (0)