diff --git a/src/Parser.php b/src/Parser.php index 6019e86..325cf85 100644 --- a/src/Parser.php +++ b/src/Parser.php @@ -2,6 +2,7 @@ namespace Differ\Parser; +use Exception; use Symfony\Component\Yaml\Yaml; use function Differ\Formatters\selectFormatter; @@ -11,13 +12,16 @@ function parse(array $resultDiff, string $format): string return selectFormatter($resultDiff, $format); } +/** + * @throws Exception + */ function parseToJson(string $path): array { $content = getFileContent($path); $offset = strpos($path, '.'); if ($offset === false) { - throw new \Exception("Incorrect path"); + throw new Exception("Incorrect path: {$path}"); } $extension = substr($path, $offset + 1); @@ -25,10 +29,13 @@ function parseToJson(string $path): array return match ($extension) { 'json' => json_decode($content, true), 'yaml' => Yaml::parse($content), - default => throw new \Exception("There is no such extension: {$extension}") + default => throw new Exception("The file format is not supported by the current version of the program: {$extension}") }; } +/** + * @throws Exception + */ function getFileContent(string $path): string { $dirPath = __DIR__; @@ -40,7 +47,7 @@ function getFileContent(string $path): string } if (!file_exists($fullPath)) { - throw new \Exception("Incorrect path"); + throw new Exception("File does not exist: {$path}"); } return file_get_contents($fullPath);