JuliaStrelkova/project-lvl2-s427

View on GitHub
src/DiffGenerator.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php
declare(strict_types=1);

namespace Gendiff;

use Gendiff\Parser\Parser;
use Gendiff\Renderer\Renderer;

class DiffGenerator
{
    private $astBuilder;
    private $parser;
    private $renderer;

    public function __construct(ASTBuilder $ASTBuilder, Parser $parser, Renderer $renderer)
    {
        $this->astBuilder = $ASTBuilder;
        $this->parser = $parser;
        $this->renderer = $renderer;
    }

    public function generateDiff(string $pathToFile1, string $pathToFile2): string
    {
        $firstDataSet = $this->parser->parse($pathToFile1);
        $secondDataSet = $this->parser->parse($pathToFile2);

        $ast = $this->astBuilder->buildAst($firstDataSet, $secondDataSet);

        return $this->renderer->render($ast);
    }
}