rector/packages/ChangesReporting/ValueObjectFactory/FileDiffFactory.php
Tomas Votruba 345a89a7e2 Updated Rector to commit a657258f31
a657258f31 cleanup CHANGELOG, is part of GitHub releases now (#2)
2021-05-10 00:23:30 +00:00

31 lines
1.2 KiB
PHP

<?php
declare (strict_types=1);
namespace Rector\ChangesReporting\ValueObjectFactory;
use Rector\Core\Differ\DefaultDiffer;
use Rector\Core\ValueObject\Application\File;
use Rector\Core\ValueObject\Reporting\FileDiff;
use RectorPrefix20210510\Symplify\ConsoleColorDiff\Console\Output\ConsoleDiffer;
final class FileDiffFactory
{
/**
* @var DefaultDiffer
*/
private $defaultDiffer;
/**
* @var ConsoleDiffer
*/
private $consoleDiffer;
public function __construct(\Rector\Core\Differ\DefaultDiffer $defaultDiffer, \RectorPrefix20210510\Symplify\ConsoleColorDiff\Console\Output\ConsoleDiffer $consoleDiffer)
{
$this->defaultDiffer = $defaultDiffer;
$this->consoleDiffer = $consoleDiffer;
}
public function createFileDiff(\Rector\Core\ValueObject\Application\File $file, string $oldContent, string $newContent) : \Rector\Core\ValueObject\Reporting\FileDiff
{
// always keep the most recent diff
return new \Rector\Core\ValueObject\Reporting\FileDiff($file->getSmartFileInfo(), $this->defaultDiffer->diff($oldContent, $newContent), $this->consoleDiffer->diff($oldContent, $newContent), $file->getRectorWithLineChanges());
}
}