Skip to content

Commit 86b5f89

Browse files
Fix
1 parent 342a39c commit 86b5f89

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/Parser.php

+13-3
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,17 @@ function parse(array $resultDiff, string $format): string
1414
function parseToJson(string $path): array
1515
{
1616
$content = getFileContent($path);
17-
$extension = substr($path, strpos($path, '.'));
17+
$offset = strpos($path, '.') + 1;
18+
19+
if ($offset === false) {
20+
throw new \Exception("Incorrect path");
21+
}
22+
23+
$extension = substr($path, $offset);
1824

1925
return match ($extension) {
20-
'.json' => json_decode($content, true),
21-
'.yaml' => Yaml::parse($content),
26+
'json' => json_decode($content, true),
27+
'yaml' => Yaml::parse($content),
2228
default => throw new \Exception("There is no such extension: {$extension}")
2329
};
2430
}
@@ -33,5 +39,9 @@ function getFileContent(string $path): string
3339
$fullPath = "{$dirPath}/../../{$path}";
3440
}
3541

42+
if (!file_exists($fullPath)) {
43+
throw new \Exception("Incorrect path");
44+
}
45+
3646
return file_get_contents($fullPath);
3747
}

0 commit comments

Comments
 (0)