caviarman/project-lvl2-s349

View on GitHub
src/Parser.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php

namespace App\Parser;

use Symfony\Component\Yaml\Yaml;

function parse($extension, $data)
{
    $parsers = [
        'json' => function ($data) {
            return json_decode($data, true);
        },
        'yaml' => function ($data) {
            return Yaml::parse($data);
        }
    ];
    return $parsers[$extension]($data);
}