Skip to content

Commit

Permalink
[Core][e2e] Handle space before content and space before open tag on …
Browse files Browse the repository at this point in the history
…deep content on PhpFileProcessor (#3418)

* [Core][e2e] Handle space and open tag on deep content on PhpFileProcessor

* Fixed 🎉

* clean up

* cs fix

* clean up
  • Loading branch information
samsonasik committed Feb 26, 2023
1 parent a8731b5 commit 8d9ff0a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
10 changes: 10 additions & 0 deletions e2e/plain-views/src/short_open_tag_and_space_before.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

<?php
function test_callback() {
// var_dump($output);
?>
<div class="wrap">
<img src="<?= escape('hi there'); ?>">
</div>
<?php
}
7 changes: 4 additions & 3 deletions src/Application/FileProcessor/PhpFileProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,16 +163,17 @@ private function printFile(File $file, Configuration $configuration): void
* On very first content level
*/
$originalFileContent = $file->getOriginalFileContent();
if (ltrim($originalFileContent) === $newContent) {
$ltrimOriginalFileContent = ltrim($originalFileContent);

if ($ltrimOriginalFileContent === $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) {
if (Strings::replace($ltrimOriginalFileContent, self::OPEN_TAG_SPACED_REGEX, '<?php') === $newContent) {
return;
}
}
Expand Down

0 comments on commit 8d9ff0a

Please sign in to comment.