Skip to content

Commit

Permalink
[Printer] Handle commented code before closing tag on no rule applied…
Browse files Browse the repository at this point in the history
… print on PhpFileProcessor (#3488)

* add failing plain view test fixture

* Closes #3486 Fixes rectorphp/rector#7845 Fixes rectorphp/rector#7841

* more fixture

---------

Co-authored-by: schlndh <schlndh@users.noreply.github.com>
  • Loading branch information
samsonasik and schlndh committed Mar 18, 2023
1 parent 4225ebf commit fd7a99a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
6 changes: 6 additions & 0 deletions e2e/plain-views/src/comment_before_closing_tag.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<div>
<?php foreach ($arr as $a) {
// aaa
?>
<?php } ?>
</div>
15 changes: 15 additions & 0 deletions e2e/plain-views/src/comment_before_closing_tag2.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<div>
<h4>
List of users
</h4>
<ul>
<?php foreach ($users as $user): ?>
<li>
<?php
echo $user['name'];
// echo "laskdjflaksdfjlsjf";
?>
</li>
<?php endforeach; ?>
</ul>
</div>
5 changes: 4 additions & 1 deletion src/Application/FileProcessor/PhpFileProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,14 @@ private function printFile(File $file, Configuration $configuration): void
return;
}

$cleanOriginalContent = Strings::replace($ltrimOriginalFileContent, self::OPEN_TAG_SPACED_REGEX, '<?php');
$cleanNewContent = Strings::replace($newContent, self::OPEN_TAG_SPACED_REGEX, '<?php');

/**
* Handle space before <?php wiped on print format preserving
* On inside content level
*/
if (Strings::replace($ltrimOriginalFileContent, self::OPEN_TAG_SPACED_REGEX, '<?php') === $newContent) {
if ($cleanOriginalContent === $cleanNewContent) {
return;
}
}
Expand Down

0 comments on commit fd7a99a

Please sign in to comment.