geozhur/project-lvl2-s337

View on GitHub
src/Parsers.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php
namespace GenDiff\Parsers;

use Symfony\Component\Yaml\Yaml;
use Exception;

function parse($content, $format)
{
    switch ($format) {
        case 'json':
            return json_decode($content);
        case 'yaml':
            return Yaml::parse($content, Yaml::PARSE_OBJECT_FOR_MAP);
        default:
            throw new \Exception("Unable parse to string\n");
    }
}