Updated Rector to commit f60aaa59539dfa31b03085ba0747a73b1815d23e

f60aaa5953 [Core] Handle space removed on no rules applied on PhpFileProcessor  (#3412)
This commit is contained in:
Tomas Votruba 2023-02-25 12:53:14 +00:00
parent 105747beb9
commit acd9d65c74
6 changed files with 49 additions and 18 deletions

View File

@ -3,6 +3,7 @@
declare (strict_types=1);
namespace Rector\Core\Application\FileProcessor;
use RectorPrefix202302\Nette\Utils\Strings;
use PHPStan\AnalysedCodeException;
use Rector\ChangesReporting\ValueObjectFactory\ErrorFactory;
use Rector\Core\Application\FileDecorator\FileDiffFileDecorator;
@ -24,6 +25,11 @@ use Rector\Testing\PHPUnit\StaticPHPUnitEnvironment;
use Throwable;
final class PhpFileProcessor implements FileProcessorInterface
{
/**
* @var string
* @see https://regex101.com/r/xP2MGa/1
*/
private const OPEN_TAG_SPACED_REGEX = '#^(?<open_tag_spaced>[^\\S\\r\\n]+\\<\\?php)#m';
/**
* @readonly
* @var \Rector\Core\PhpParser\Printer\FormatPerservingPrinter
@ -161,7 +167,34 @@ final class PhpFileProcessor implements FileProcessorInterface
// skip, because this file exists no more
return;
}
$newContent = $configuration->isDryRun() ? $this->formatPerservingPrinter->printParsedStmstAndTokensToString($file) : $this->formatPerservingPrinter->printParsedStmstAndTokens($file);
// only save to string first, no need to print to file when not needed
$newContent = $this->formatPerservingPrinter->printParsedStmstAndTokensToString($file);
/**
* When no Rules applied, the PostRector may still change the content, that's why printing still needed
* On printing, the space may be wiped, these below check compare with original file content used to verify
* that no diff actually needed
*/
if ($file->getRectorWithLineChanges() === []) {
/**
* Handle new line or space before <?php or InlineHTML node wiped on print format preserving
* On very first content level
*/
$originalFileContent = $file->getOriginalFileContent();
if (\ltrim($originalFileContent) === $newContent) {
return;
}
/**
* Handle space before <?php wiped on print format preserving
* On inside content level
*/
$cleanedOriginalFileContent = Strings::replace($originalFileContent, self::OPEN_TAG_SPACED_REGEX, '<?php');
if ($cleanedOriginalFileContent === $newContent) {
return;
}
}
if (!$configuration->isDryRun()) {
$this->formatPerservingPrinter->dumpFile($file->getFilePath(), $newContent);
}
$file->changeFileContent($newContent);
$this->fileDiffFileDecorator->decorate([$file]);
}

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '7a6531d32db4db72241628feb6f8257e2df3720e';
public const PACKAGE_VERSION = 'f60aaa59539dfa31b03085ba0747a73b1815d23e';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2023-02-25 02:38:08';
public const RELEASE_DATE = '2023-02-25 12:48:50';
/**
* @var int
*/

View File

@ -36,17 +36,15 @@ final class FormatPerservingPrinter
public function printToFile(string $filePath, array $newStmts, array $oldStmts, array $oldTokens) : string
{
$newContent = $this->betterStandardPrinter->printFormatPreserving($newStmts, $oldStmts, $oldTokens);
$this->filesystem->dumpFile($filePath, $newContent);
// @todo how to keep origianl access rights without the SplFileInfo
// $this->filesystem->chmod($filePath, $fileInfo->getPerms());
$this->dumpFile($filePath, $newContent);
return $newContent;
}
public function printParsedStmstAndTokensToString(File $file) : string
{
return $this->betterStandardPrinter->printFormatPreserving($file->getNewStmts(), $file->getOldStmts(), $file->getOldTokens());
}
public function printParsedStmstAndTokens(File $file) : string
public function dumpFile(string $filePath, string $newContent) : void
{
return $this->printToFile($file->getFilePath(), $file->getNewStmts(), $file->getOldStmts(), $file->getOldTokens());
$this->filesystem->dumpFile($filePath, $newContent);
}
}

2
vendor/autoload.php vendored
View File

@ -22,4 +22,4 @@ if (PHP_VERSION_ID < 50600) {
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInit679bd58aa1f6675bcf4835931cf4d324::getLoader();
return ComposerAutoloaderInitdbbcf9be257bf52efb0f8ce767c0f8ce::getLoader();

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit679bd58aa1f6675bcf4835931cf4d324
class ComposerAutoloaderInitdbbcf9be257bf52efb0f8ce767c0f8ce
{
private static $loader;
@ -22,17 +22,17 @@ class ComposerAutoloaderInit679bd58aa1f6675bcf4835931cf4d324
return self::$loader;
}
spl_autoload_register(array('ComposerAutoloaderInit679bd58aa1f6675bcf4835931cf4d324', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInitdbbcf9be257bf52efb0f8ce767c0f8ce', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
spl_autoload_unregister(array('ComposerAutoloaderInit679bd58aa1f6675bcf4835931cf4d324', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInitdbbcf9be257bf52efb0f8ce767c0f8ce', 'loadClassLoader'));
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit679bd58aa1f6675bcf4835931cf4d324::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInitdbbcf9be257bf52efb0f8ce767c0f8ce::getInitializer($loader));
$loader->setClassMapAuthoritative(true);
$loader->register(true);
$filesToLoad = \Composer\Autoload\ComposerStaticInit679bd58aa1f6675bcf4835931cf4d324::$files;
$filesToLoad = \Composer\Autoload\ComposerStaticInitdbbcf9be257bf52efb0f8ce767c0f8ce::$files;
$requireFile = \Closure::bind(static function ($fileIdentifier, $file) {
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;

View File

@ -4,7 +4,7 @@
namespace Composer\Autoload;
class ComposerStaticInit679bd58aa1f6675bcf4835931cf4d324
class ComposerStaticInitdbbcf9be257bf52efb0f8ce767c0f8ce
{
public static $files = array (
'ad155f8f1cf0d418fe49e248db8c661b' => __DIR__ . '/..' . '/react/promise/src/functions_include.php',
@ -3125,9 +3125,9 @@ class ComposerStaticInit679bd58aa1f6675bcf4835931cf4d324
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit679bd58aa1f6675bcf4835931cf4d324::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit679bd58aa1f6675bcf4835931cf4d324::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit679bd58aa1f6675bcf4835931cf4d324::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInitdbbcf9be257bf52efb0f8ce767c0f8ce::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInitdbbcf9be257bf52efb0f8ce767c0f8ce::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInitdbbcf9be257bf52efb0f8ce767c0f8ce::$classMap;
}, null, ClassLoader::class);
}