Skip to content

Commit 0b4029e

Browse files
committed
Updated Rector to commit bdc09071abc58550a41fdd8a4af515206e022f4c
rectorphp/rector-src@bdc0907 fix: Strip left spaces from opening tags when comparing output for changes (#5701)
1 parent 2ede0d9 commit 0b4029e

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

src/Application/FileProcessor.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use Rector\ValueObject\Reporting\FileDiff;
2424
use RectorPrefix202403\Symfony\Component\Console\Style\SymfonyStyle;
2525
use Throwable;
26+
use RectorPrefix202403\Nette\Utils\Strings;
2627
final class FileProcessor
2728
{
2829
/**
@@ -75,6 +76,11 @@ final class FileProcessor
7576
* @var \Rector\NodeTypeResolver\NodeScopeAndMetadataDecorator
7677
*/
7778
private $nodeScopeAndMetadataDecorator;
79+
/**
80+
* @var string
81+
* @see https://regex101.com/r/llm7XZ/1
82+
*/
83+
private const OPEN_TAG_SPACED_REGEX = '#^[ \\t]+<\\?php#m';
7884
public function __construct(FormatPerservingPrinter $formatPerservingPrinter, RectorNodeTraverser $rectorNodeTraverser, SymfonyStyle $symfonyStyle, FileDiffFactory $fileDiffFactory, ChangedFilesDetector $changedFilesDetector, ErrorFactory $errorFactory, FilePathHelper $filePathHelper, PostFileProcessor $postFileProcessor, RectorParser $rectorParser, NodeScopeAndMetadataDecorator $nodeScopeAndMetadataDecorator)
7985
{
8086
$this->formatPerservingPrinter = $formatPerservingPrinter;
@@ -162,11 +168,16 @@ private function printFile(File $file, Configuration $configuration, string $fil
162168
* Handle new line or space before <?php or InlineHTML node wiped on print format preserving
163169
* On very first content level
164170
*/
165-
$originalFileContent = $file->getOriginalFileContent();
166-
$ltrimOriginalFileContent = \ltrim($originalFileContent);
171+
$ltrimOriginalFileContent = \ltrim($file->getOriginalFileContent());
167172
if ($ltrimOriginalFileContent === $newContent) {
168173
return;
169174
}
175+
// handle space before <?php
176+
$ltrimNewContent = Strings::replace($newContent, self::OPEN_TAG_SPACED_REGEX, '<?php');
177+
$ltrimOriginalFileContent = Strings::replace($ltrimOriginalFileContent, self::OPEN_TAG_SPACED_REGEX, '<?php');
178+
if ($ltrimOriginalFileContent === $ltrimNewContent) {
179+
return;
180+
}
170181
}
171182
// change file content early to make $file->hasChanged() based on new content
172183
$file->changeFileContent($newContent);

src/Application/VersionResolver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ final class VersionResolver
1919
* @api
2020
* @var string
2121
*/
22-
public const PACKAGE_VERSION = 'e4b6ee63140c90c18f1fa51156ccffa569f1062c';
22+
public const PACKAGE_VERSION = 'bdc09071abc58550a41fdd8a4af515206e022f4c';
2323
/**
2424
* @api
2525
* @var string
2626
*/
27-
public const RELEASE_DATE = '2024-03-10 00:27:19';
27+
public const RELEASE_DATE = '2024-03-10 16:21:31';
2828
/**
2929
* @var int
3030
*/

0 commit comments

Comments
 (0)