Skip to content

Commit

Permalink
[Core] Remove template-extends check as well on FileProcessor (#1098)
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed Oct 29, 2021
1 parent 4c50763 commit 0db02e2
Showing 1 changed file with 1 addition and 31 deletions.
32 changes: 1 addition & 31 deletions src/Application/FileProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,19 @@

namespace Rector\Core\Application;

use Nette\Utils\Strings;
use PhpParser\Node;
use Rector\ChangesReporting\Collector\AffectedFilesCollector;
use Rector\Core\PhpParser\NodeTraverser\RectorNodeTraverser;
use Rector\Core\PhpParser\Parser\RectorParser;
use Rector\Core\PhpParser\Printer\BetterStandardPrinter;
use Rector\Core\ValueObject\Application\File;
use Rector\NodeTypeResolver\NodeScopeAndMetadataDecorator;

final class FileProcessor
{
/**
* @var string
* @see https://regex101.com/r/ozPuC9/1
*/
public const TEMPLATE_EXTENDS_REGEX = '#(\*|\/\/)\s+\@template-extends\s+\\\\?\w+#';

public function __construct(
private AffectedFilesCollector $affectedFilesCollector,
private NodeScopeAndMetadataDecorator $nodeScopeAndMetadataDecorator,
private RectorParser $rectorParser,
private RectorNodeTraverser $rectorNodeTraverser,
private BetterStandardPrinter $betterStandardPrinter
private RectorNodeTraverser $rectorNodeTraverser
) {
}

Expand All @@ -39,17 +29,6 @@ public function parseFileInfoToLocalCache(File $file): void
$oldStmts = $stmtsAndTokens->getStmts();
$oldTokens = $stmtsAndTokens->getTokens();

/**
* Tweak PHPStan internal issue for has @template-extends that cause endless loop in the process
*
* @see https://github.com/phpstan/phpstan/issues/3865
* @see https://github.com/rectorphp/rector/issues/6758
*/
if ($this->isTemplateExtendsInSource($oldStmts)) {
$file->hydrateStmtsAndTokens($oldStmts, $oldStmts, $oldTokens);
return;
}

// @todo may need tweak to refresh PHPStan types to avoid issue like in https://github.com/rectorphp/rector/issues/6561
$newStmts = $this->nodeScopeAndMetadataDecorator->decorateNodesFromFile($file, $oldStmts);
$file->hydrateStmtsAndTokens($newStmts, $oldStmts, $oldTokens);
Expand All @@ -65,13 +44,4 @@ public function refactor(File $file): void
$this->refactor($otherTouchedFile);
}
}

/**
* @param Node[] $nodes
*/
private function isTemplateExtendsInSource(array $nodes): bool
{
$print = $this->betterStandardPrinter->print($nodes);
return (bool) Strings::match($print, self::TEMPLATE_EXTENDS_REGEX);
}
}

0 comments on commit 0db02e2

Please sign in to comment.