mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-11 21:52:21 +00:00
f010267a7c
6b69971dfc
[NodeTypeCorrector] Directly use StringType on Intersection of strings on AccessoryNonEmptyStringTypeCorrector (#5933)
45 lines
1.4 KiB
PHP
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);
|
|
}
|
|
}
|