Skip to content

Commit 18c78b4

Browse files
Reafactoring Parser: add match instead of if
1 parent efdcc20 commit 18c78b4

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/Parser.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ function parse(array $resultDiff, string $format): string
1414
function parseToJson(string $path): array
1515
{
1616
$content = getFileContent($path);
17+
$extension = substr($path, strpos($path, '.') + 1);
1718

18-
if (str_ends_with($path, '.yaml') || str_ends_with($path, '.yml')) {
19-
return Yaml::parse($content);
20-
}
21-
22-
return json_decode($content, true);
19+
return match ($extension) {
20+
'json' => json_decode($content, true),
21+
'yaml' => Yaml::parse($content)
22+
};
2323
}
2424

2525
function getFileContent(string $path): string

0 commit comments

Comments
 (0)