caviarman/project-lvl2-s349

View on GitHub
src/Renderers/Renderer.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php

namespace App\Renderer;

use function Funct\Collection\flattenAll;

function render($ast, $format)
{
    $formats = [
        'pretty' => function ($ast) {
            return pretty($ast);
        },
        'plain' => function ($ast) {
            return plain($ast);
        },
        'json' => function ($ast) {
            return json_encode($ast, JSON_PRETTY_PRINT);
        }
    ];
    return $formats[$format]($ast);
}