vadshevy/php-project-lvl2

View on GitHub
src/parsers.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php

namespace Gendiff\parsers;

use Symfony\Component\Yaml\Yaml;

function parse($data, $dataType)
{
    switch ($dataType) {
        case 'json':
            return json_decode($data);
        case 'yml':
        case 'yaml':
            return Yaml::parse($data, Yaml::PARSE_OBJECT_FOR_MAP);
        default:
            throw new \Exception("Invalid input format {$dataType}");
    }
}