Skip to content

Commit

Permalink
[Performance] Remove regex check on open tag spaced check on FileProc…
Browse files Browse the repository at this point in the history
…essor (#5073)

* [Performance] Remove regex check on open tag spaced check on FileProcessor

* fixtures

* clean up
  • Loading branch information
samsonasik committed Sep 23, 2023
1 parent 8bfaf45 commit 59e25d9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
18 changes: 0 additions & 18 deletions src/Application/FileProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Rector\Core\Application;

use Nette\Utils\Strings;
use PHPStan\AnalysedCodeException;
use Rector\Caching\Detector\ChangedFilesDetector;
use Rector\ChangesReporting\ValueObjectFactory\ErrorFactory;
Expand All @@ -29,12 +28,6 @@

final class FileProcessor
{
/**
* @var string
* @see https://regex101.com/r/xP2MGa/1
*/
private const OPEN_TAG_SPACED_REGEX = '#^(?<open_tag_spaced>[^\S\r\n]+\<\?php)#m';

public function __construct(
private readonly FormatPerservingPrinter $formatPerservingPrinter,
private readonly RectorNodeTraverser $rectorNodeTraverser,
Expand Down Expand Up @@ -164,17 +157,6 @@ private function printFile(File $file, Configuration $configuration): void
if ($ltrimOriginalFileContent === $newContent) {
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 ($cleanOriginalContent === $cleanNewContent) {
return;
}
}

if (! $configuration->isDryRun()) {
Expand Down
10 changes: 10 additions & 0 deletions tests/Issues/NoNamespaced/Fixture/open_tag_spaced.php.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
function test_callback2() {
// var_dump($output);
?>
<div class="wrap">
<img src="<?= escape('hi there'); ?>">
</div>
<?php
echo " <?php";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@


<?php

echo 'no change, has space before open tag';

0 comments on commit 59e25d9

Please sign in to comment.