caviarman/project-lvl2-s349

View on GitHub
src/Diff.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php

namespace App\Diff;

use function App\Parser\parse;
use function App\Ast\getAst;
use function App\Renderer\render;
use function Funct\Collection\flattenAll;

function boolToStr($bool)
{
    return $bool ? 'true' : 'false';
}
function getExtension($path)
{
    return pathinfo($path, PATHINFO_EXTENSION);
}
function getData($path)
{
    return file_get_contents($path, true);
}

function genDiff($pathBefore, $pathAfter, $format)
{
    $before = parse(getExtension($pathBefore), getData($pathBefore));
    $after = parse(getExtension($pathAfter), getData($pathAfter));
    $ast = getAst($before, $after);
    return render($ast, $format);
}