rector/src/PhpParser/Printer/FormatPerservingPrinter.php
Tomas Votruba f010267a7c Updated Rector to commit 6b69971dfc740a58aed918782d02710e42004e9d
6b69971dfc [NodeTypeCorrector] Directly use StringType on Intersection of strings on AccessoryNonEmptyStringTypeCorrector (#5933)
2024-06-01 09:25:16 +00:00

45 lines
1.4 KiB
PHP

<?php
declare (strict_types=1);
namespace Rector\PhpParser\Printer;
use RectorPrefix202406\Nette\Utils\FileSystem;
use PhpParser\Node;
use Rector\ValueObject\Application\File;
/**
* @see \Rector\Tests\PhpParser\Printer\FormatPerservingPrinterTest
*/
final class FormatPerservingPrinter
{
/**
* @readonly
* @var \Rector\PhpParser\Printer\BetterStandardPrinter
*/
private $betterStandardPrinter;
public function __construct(\Rector\PhpParser\Printer\BetterStandardPrinter $betterStandardPrinter)
{
$this->betterStandardPrinter = $betterStandardPrinter;
}
/**
* @api tests
*
* @param Node[] $newStmts
* @param Node[] $oldStmts
* @param Node[] $oldTokens
*/
public function printToFile(string $filePath, array $newStmts, array $oldStmts, array $oldTokens) : string
{
$newContent = $this->betterStandardPrinter->printFormatPreserving($newStmts, $oldStmts, $oldTokens);
$this->dumpFile($filePath, $newContent);
return $newContent;
}
public function printParsedStmstAndTokensToString(File $file) : string
{
return $this->betterStandardPrinter->printFormatPreserving($file->getNewStmts(), $file->getOldStmts(), $file->getOldTokens());
}
public function dumpFile(string $filePath, string $newContent) : void
{
FileSystem::write($filePath, $newContent, null);
}
}