Cabyca/php-project-lvl2

View on GitHub
src/Parser.php

Summary

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

namespace Differ\Parser;

use Symfony\Component\Yaml\Yaml;

function parser($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("Unknown data type: $dataType");
    }
}