mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-05 10:50:48 +00:00
45 lines
1.0 KiB
PHP
45 lines
1.0 KiB
PHP
<?php declare(strict_types=1);
|
|
|
|
namespace Rector\Printer;
|
|
|
|
use PhpParser\Node;
|
|
use PhpParser\PrettyPrinter\Standard;
|
|
use SplFileInfo;
|
|
|
|
final class FormatPerservingPrinter
|
|
{
|
|
/**
|
|
* @var Standard
|
|
*/
|
|
private $prettyPrinter;
|
|
|
|
public function __construct(Standard $prettyPrinter)
|
|
{
|
|
$this->prettyPrinter = $prettyPrinter;
|
|
}
|
|
|
|
/**
|
|
* @param Node[] $newStmts
|
|
* @param Node[] $oldStmts
|
|
* @param Node[] $oldTokens
|
|
*/
|
|
public function printToFile(SplFileInfo $file, array $newStmts, array $oldStmts, array $oldTokens): void
|
|
{
|
|
if ($oldStmts === $newStmts) {
|
|
return;
|
|
}
|
|
|
|
file_put_contents($file->getRealPath(), $this->printToString($newStmts, $oldStmts, $oldTokens));
|
|
}
|
|
|
|
/**
|
|
* @param Node[] $newStmts
|
|
* @param Node[] $oldStmts
|
|
* @param Node[] $oldTokens
|
|
*/
|
|
public function printToString(array $newStmts, array $oldStmts, array $oldTokens): string
|
|
{
|
|
return $this->prettyPrinter->printFormatPreserving($newStmts, $oldStmts, $oldTokens);
|
|
}
|
|
}
|