hallernsk/php-project-lvl2

View on GitHub
src/Parsers.php

Summary

Maintainability
A
0 mins
Test Coverage
C
71%
<?php

namespace Differ\Parsers;

use Symfony\Component\Yaml\Yaml;

function parse(string $data, string $format): array
{
    switch ($format) {
        case 'json':
            return json_decode($data, true);

        case 'yml':
        case 'yaml':
            return Yaml::parse($data);

        default:
            throw new \Exception("Incorrect file format: $format");
    }
}