mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-07 03:40:50 +00:00
Updated Rector to commit c3aca95a7d1281beee8850ae001952760cce6658
c3aca95a7d
Calculate diff only once per file after refactoring (#3711)
This commit is contained in:
parent
442ebde599
commit
4a2e921404
|
@ -3,6 +3,7 @@
|
|||
declare (strict_types=1);
|
||||
namespace Rector\ChangesReporting\ValueObjectFactory;
|
||||
|
||||
use Rector\ChangesReporting\ValueObject\RectorWithLineChange;
|
||||
use Rector\Core\Console\Formatter\ConsoleDiffer;
|
||||
use Rector\Core\Differ\DefaultDiffer;
|
||||
use Rector\Core\FileSystem\FilePathHelper;
|
||||
|
@ -32,9 +33,20 @@ final class FileDiffFactory
|
|||
$this->filePathHelper = $filePathHelper;
|
||||
}
|
||||
public function createFileDiff(File $file, string $oldContent, string $newContent) : FileDiff
|
||||
{
|
||||
return $this->createFileDiffWithLineChanges($file, $oldContent, $newContent, $file->getRectorWithLineChanges());
|
||||
}
|
||||
/**
|
||||
* @param RectorWithLineChange[] $rectorsWithLineChanges
|
||||
*/
|
||||
public function createFileDiffWithLineChanges(File $file, string $oldContent, string $newContent, array $rectorsWithLineChanges) : FileDiff
|
||||
{
|
||||
$relativeFilePath = $this->filePathHelper->relativePath($file->getFilePath());
|
||||
// always keep the most recent diff
|
||||
return new FileDiff($relativeFilePath, $this->defaultDiffer->diff($oldContent, $newContent), $this->consoleDiffer->diff($oldContent, $newContent), $file->getRectorWithLineChanges());
|
||||
return new FileDiff($relativeFilePath, $this->defaultDiffer->diff($oldContent, $newContent), $this->consoleDiffer->diff($oldContent, $newContent), $rectorsWithLineChanges);
|
||||
}
|
||||
public function createTempFileDiff(File $file) : FileDiff
|
||||
{
|
||||
return $this->createFileDiffWithLineChanges($file, '', '', $file->getRectorWithLineChanges());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,7 @@ namespace Rector\Core\Application\FileProcessor;
|
|||
use RectorPrefix202304\Nette\Utils\Strings;
|
||||
use PHPStan\AnalysedCodeException;
|
||||
use Rector\ChangesReporting\ValueObjectFactory\ErrorFactory;
|
||||
use Rector\Core\Application\FileDecorator\FileDiffFileDecorator;
|
||||
use Rector\ChangesReporting\ValueObjectFactory\FileDiffFactory;
|
||||
use Rector\Core\Application\FileProcessor;
|
||||
use Rector\Core\Application\FileSystem\RemovedAndAddedFilesCollector;
|
||||
use Rector\Core\Contract\Console\OutputStyleInterface;
|
||||
|
@ -52,9 +52,9 @@ final class PhpFileProcessor implements FileProcessorInterface
|
|||
private $rectorOutputStyle;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Core\Application\FileDecorator\FileDiffFileDecorator
|
||||
* @var \Rector\ChangesReporting\ValueObjectFactory\FileDiffFactory
|
||||
*/
|
||||
private $fileDiffFileDecorator;
|
||||
private $fileDiffFactory;
|
||||
/**
|
||||
* @readonly
|
||||
* @var \Rector\Core\Provider\CurrentFileProvider
|
||||
|
@ -75,13 +75,13 @@ final class PhpFileProcessor implements FileProcessorInterface
|
|||
* @var \Rector\Core\FileSystem\FilePathHelper
|
||||
*/
|
||||
private $filePathHelper;
|
||||
public function __construct(FormatPerservingPrinter $formatPerservingPrinter, FileProcessor $fileProcessor, RemovedAndAddedFilesCollector $removedAndAddedFilesCollector, OutputStyleInterface $rectorOutputStyle, FileDiffFileDecorator $fileDiffFileDecorator, CurrentFileProvider $currentFileProvider, PostFileProcessor $postFileProcessor, ErrorFactory $errorFactory, FilePathHelper $filePathHelper)
|
||||
public function __construct(FormatPerservingPrinter $formatPerservingPrinter, FileProcessor $fileProcessor, RemovedAndAddedFilesCollector $removedAndAddedFilesCollector, OutputStyleInterface $rectorOutputStyle, FileDiffFactory $fileDiffFactory, CurrentFileProvider $currentFileProvider, PostFileProcessor $postFileProcessor, ErrorFactory $errorFactory, FilePathHelper $filePathHelper)
|
||||
{
|
||||
$this->formatPerservingPrinter = $formatPerservingPrinter;
|
||||
$this->fileProcessor = $fileProcessor;
|
||||
$this->removedAndAddedFilesCollector = $removedAndAddedFilesCollector;
|
||||
$this->rectorOutputStyle = $rectorOutputStyle;
|
||||
$this->fileDiffFileDecorator = $fileDiffFileDecorator;
|
||||
$this->fileDiffFactory = $fileDiffFactory;
|
||||
$this->currentFileProvider = $currentFileProvider;
|
||||
$this->postFileProcessor = $postFileProcessor;
|
||||
$this->errorFactory = $errorFactory;
|
||||
|
@ -101,6 +101,7 @@ final class PhpFileProcessor implements FileProcessorInterface
|
|||
return $systemErrorsAndFileDiffs;
|
||||
}
|
||||
// 2. change nodes with Rectors
|
||||
$rectorWithLineChanges = null;
|
||||
do {
|
||||
$file->changeHasChanged(\false);
|
||||
$this->fileProcessor->refactor($file, $configuration);
|
||||
|
@ -111,7 +112,14 @@ final class PhpFileProcessor implements FileProcessorInterface
|
|||
// 4. print to file or string
|
||||
// important to detect if file has changed
|
||||
$this->printFile($file, $configuration);
|
||||
if ($file->hasChanged()) {
|
||||
$file->setFileDiff($this->fileDiffFactory->createTempFileDiff($file));
|
||||
$rectorWithLineChanges = $file->getRectorWithLineChanges();
|
||||
}
|
||||
} while ($file->hasChanged());
|
||||
if ($configuration->shouldShowDiffs() && $rectorWithLineChanges !== null) {
|
||||
$file->setFileDiff($this->fileDiffFactory->createFileDiffWithLineChanges($file, $file->getOriginalFileContent(), $file->getFileContent(), $rectorWithLineChanges));
|
||||
}
|
||||
// return json here
|
||||
$fileDiff = $file->getFileDiff();
|
||||
if (!$fileDiff instanceof FileDiff) {
|
||||
|
@ -198,9 +206,6 @@ final class PhpFileProcessor implements FileProcessorInterface
|
|||
$this->formatPerservingPrinter->dumpFile($file->getFilePath(), $newContent);
|
||||
}
|
||||
$file->changeFileContent($newContent);
|
||||
if ($configuration->shouldShowDiffs()) {
|
||||
$this->fileDiffFileDecorator->decorate([$file]);
|
||||
}
|
||||
}
|
||||
private function notifyFile(File $file) : void
|
||||
{
|
||||
|
|
|
@ -19,12 +19,12 @@ final class VersionResolver
|
|||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = 'a39913ec9e3216b61fea7c90b634bc5a404323cf';
|
||||
public const PACKAGE_VERSION = 'c3aca95a7d1281beee8850ae001952760cce6658';
|
||||
/**
|
||||
* @api
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2023-04-30 00:37:30';
|
||||
public const RELEASE_DATE = '2023-04-30 09:30:11';
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
|
|
2
vendor/autoload.php
vendored
2
vendor/autoload.php
vendored
|
@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
|
|||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInite71c077ab5c2d18410daf172e2b3710d::getLoader();
|
||||
return ComposerAutoloaderInita83d01ab291c56a79faed0c7e78fc6f0::getLoader();
|
||||
|
|
10
vendor/composer/autoload_real.php
vendored
10
vendor/composer/autoload_real.php
vendored
|
@ -2,7 +2,7 @@
|
|||
|
||||
// autoload_real.php @generated by Composer
|
||||
|
||||
class ComposerAutoloaderInite71c077ab5c2d18410daf172e2b3710d
|
||||
class ComposerAutoloaderInita83d01ab291c56a79faed0c7e78fc6f0
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
|
@ -22,17 +22,17 @@ class ComposerAutoloaderInite71c077ab5c2d18410daf172e2b3710d
|
|||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInite71c077ab5c2d18410daf172e2b3710d', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInita83d01ab291c56a79faed0c7e78fc6f0', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInite71c077ab5c2d18410daf172e2b3710d', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInita83d01ab291c56a79faed0c7e78fc6f0', 'loadClassLoader'));
|
||||
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInite71c077ab5c2d18410daf172e2b3710d::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInita83d01ab291c56a79faed0c7e78fc6f0::getInitializer($loader));
|
||||
|
||||
$loader->setClassMapAuthoritative(true);
|
||||
$loader->register(true);
|
||||
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInite71c077ab5c2d18410daf172e2b3710d::$files;
|
||||
$filesToLoad = \Composer\Autoload\ComposerStaticInita83d01ab291c56a79faed0c7e78fc6f0::$files;
|
||||
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
|
||||
|
|
8
vendor/composer/autoload_static.php
vendored
8
vendor/composer/autoload_static.php
vendored
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInite71c077ab5c2d18410daf172e2b3710d
|
||||
class ComposerStaticInita83d01ab291c56a79faed0c7e78fc6f0
|
||||
{
|
||||
public static $files = array (
|
||||
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
|
||||
|
@ -3152,9 +3152,9 @@ class ComposerStaticInite71c077ab5c2d18410daf172e2b3710d
|
|||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInite71c077ab5c2d18410daf172e2b3710d::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInite71c077ab5c2d18410daf172e2b3710d::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInite71c077ab5c2d18410daf172e2b3710d::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInita83d01ab291c56a79faed0c7e78fc6f0::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInita83d01ab291c56a79faed0c7e78fc6f0::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInita83d01ab291c56a79faed0c7e78fc6f0::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user