diff --git a/rules/CodeQuality/Rector/Expression/TernaryFalseExpressionToIfRector.php b/rules/CodeQuality/Rector/Expression/TernaryFalseExpressionToIfRector.php index f2b6d6558da..97beb61566d 100644 --- a/rules/CodeQuality/Rector/Expression/TernaryFalseExpressionToIfRector.php +++ b/rules/CodeQuality/Rector/Expression/TernaryFalseExpressionToIfRector.php @@ -10,7 +10,6 @@ use PhpParser\Node\Expr\Variable; use PhpParser\Node\Stmt\Expression; use PhpParser\Node\Stmt\If_; -use Rector\Contract\Rector\HTMLAverseRectorInterface; use Rector\NodeAnalyzer\ExprAnalyzer; use Rector\Rector\AbstractRector; use Rector\RuleDoc\CodeSample\CodeSample; @@ -19,7 +18,7 @@ /** * @see \Rector\Tests\CodeQuality\Rector\Expression\TernaryFalseExpressionToIfRector\TernaryFalseExpressionToIfRectorTest */ -final class TernaryFalseExpressionToIfRector extends AbstractRector implements HTMLAverseRectorInterface +final class TernaryFalseExpressionToIfRector extends AbstractRector { public function __construct( private readonly ExprAnalyzer $exprAnalyzer @@ -69,6 +68,10 @@ public function getNodeTypes(): array */ public function refactor(Node $node): ?Node { + if ($this->getFile()->containsHTML()) { + return null; + } + if (! $node->expr instanceof Ternary) { return null; } diff --git a/rules/CodeQuality/Rector/For_/ForRepeatedCountToOwnVariableRector.php b/rules/CodeQuality/Rector/For_/ForRepeatedCountToOwnVariableRector.php index e55339f349b..0eeb546fcbb 100644 --- a/rules/CodeQuality/Rector/For_/ForRepeatedCountToOwnVariableRector.php +++ b/rules/CodeQuality/Rector/For_/ForRepeatedCountToOwnVariableRector.php @@ -14,7 +14,6 @@ use PhpParser\Node\Stmt; use PhpParser\Node\Stmt\Expression; use PhpParser\Node\Stmt\For_; -use Rector\Contract\Rector\HTMLAverseRectorInterface; use Rector\PHPStan\ScopeFetcher; use Rector\Rector\AbstractRector; use Rector\RuleDoc\CodeSample\CodeSample; @@ -23,7 +22,7 @@ /** * @see \Rector\Tests\CodeQuality\Rector\For_\ForRepeatedCountToOwnVariableRector\ForRepeatedCountToOwnVariableRectorTest */ -final class ForRepeatedCountToOwnVariableRector extends AbstractRector implements HTMLAverseRectorInterface +final class ForRepeatedCountToOwnVariableRector extends AbstractRector { private const string COUNTER_NAME = 'counter'; @@ -76,6 +75,10 @@ public function getNodeTypes(): array */ public function refactor(Node $node): ?array { + if ($this->getFile()->containsHTML()) { + return null; + } + $scope = ScopeFetcher::fetch($node); if ($scope->hasVariableType(self::COUNTER_NAME)->yes()) { diff --git a/rules/CodeQuality/Rector/If_/CompleteMissingIfElseBracketRector.php b/rules/CodeQuality/Rector/If_/CompleteMissingIfElseBracketRector.php index a1a3b9cc274..ed344de71a4 100644 --- a/rules/CodeQuality/Rector/If_/CompleteMissingIfElseBracketRector.php +++ b/rules/CodeQuality/Rector/If_/CompleteMissingIfElseBracketRector.php @@ -10,7 +10,6 @@ use PhpParser\Node\Stmt\ElseIf_; use PhpParser\Node\Stmt\If_; use PhpParser\Token; -use Rector\Contract\Rector\HTMLAverseRectorInterface; use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\Rector\AbstractRector; use Rector\RuleDoc\CodeSample\CodeSample; @@ -19,7 +18,7 @@ /** * @see \Rector\Tests\CodeQuality\Rector\If_\CompleteMissingIfElseBracketRector\CompleteMissingIfElseBracketRectorTest */ -final class CompleteMissingIfElseBracketRector extends AbstractRector implements HTMLAverseRectorInterface +final class CompleteMissingIfElseBracketRector extends AbstractRector { public function getRuleDefinition(): RuleDefinition { @@ -65,6 +64,10 @@ public function getNodeTypes(): array */ public function refactor(Node $node): ?Node { + if ($this->getFile()->containsHTML()) { + return null; + } + if ($this->isBareNewNode($node)) { return null; } diff --git a/rules/CodingStyle/Rector/ClassMethod/NewlineBeforeNewAssignSetRector.php b/rules/CodingStyle/Rector/ClassMethod/NewlineBeforeNewAssignSetRector.php index 4d0b5394598..48345dc8d71 100644 --- a/rules/CodingStyle/Rector/ClassMethod/NewlineBeforeNewAssignSetRector.php +++ b/rules/CodingStyle/Rector/ClassMethod/NewlineBeforeNewAssignSetRector.php @@ -16,7 +16,6 @@ use PhpParser\Node\Stmt\Expression; use PhpParser\Node\Stmt\Function_; use PhpParser\Node\Stmt\Nop; -use Rector\Contract\Rector\HTMLAverseRectorInterface; use Rector\Rector\AbstractRector; use Rector\RuleDoc\CodeSample\CodeSample; use Rector\RuleDoc\RuleDefinition; @@ -24,7 +23,7 @@ /** * @see \Rector\Tests\CodingStyle\Rector\ClassMethod\NewlineBeforeNewAssignSetRector\NewlineBeforeNewAssignSetRectorTest */ -final class NewlineBeforeNewAssignSetRector extends AbstractRector implements HTMLAverseRectorInterface +final class NewlineBeforeNewAssignSetRector extends AbstractRector { private ?string $previousStmtVariableName = null; @@ -87,6 +86,10 @@ public function getNodeTypes(): array */ public function refactor(Node $node): ?Node { + if ($this->getFile()->containsHTML()) { + return null; + } + // skip methods with no bodies (e.g interface methods) if ($node->stmts === null) { return null; diff --git a/rules/CodingStyle/Rector/If_/AlternativeIfToBracketRector.php b/rules/CodingStyle/Rector/If_/AlternativeIfToBracketRector.php index a716743993d..fea37ed4ba3 100644 --- a/rules/CodingStyle/Rector/If_/AlternativeIfToBracketRector.php +++ b/rules/CodingStyle/Rector/If_/AlternativeIfToBracketRector.php @@ -7,7 +7,6 @@ use PhpParser\Node; use PhpParser\Node\Stmt\If_; use PhpParser\Token; -use Rector\Contract\Rector\HTMLAverseRectorInterface; use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\Rector\AbstractRector; use Rector\RuleDoc\CodeSample\CodeSample; @@ -16,7 +15,7 @@ /** * @see \Rector\Tests\CodingStyle\Rector\If_\AlternativeIfToBracketRector\AlternativeIfToBracketRectorTest */ -final class AlternativeIfToBracketRector extends AbstractRector implements HTMLAverseRectorInterface +final class AlternativeIfToBracketRector extends AbstractRector { public function getRuleDefinition(): RuleDefinition { @@ -54,6 +53,10 @@ public function getNodeTypes(): array */ public function refactor(Node $node): ?Node { + if ($this->getFile()->containsHTML()) { + return null; + } + if (! $this->isAlternativeSyntax($node)) { return null; } diff --git a/rules/CodingStyle/Rector/Stmt/NewlineAfterStatementRector.php b/rules/CodingStyle/Rector/Stmt/NewlineAfterStatementRector.php index dcb5a200e7e..98d53c457db 100644 --- a/rules/CodingStyle/Rector/Stmt/NewlineAfterStatementRector.php +++ b/rules/CodingStyle/Rector/Stmt/NewlineAfterStatementRector.php @@ -8,7 +8,6 @@ use PhpParser\Node\Stmt; use PhpParser\Node\Stmt\Nop; use Rector\Comments\CommentResolver; -use Rector\Contract\Rector\HTMLAverseRectorInterface; use Rector\PhpParser\Enum\NodeGroup; use Rector\Rector\AbstractRector; use Rector\RuleDoc\CodeSample\CodeSample; @@ -17,7 +16,7 @@ /** * @see \Rector\Tests\CodingStyle\Rector\Stmt\NewlineAfterStatementRector\NewlineAfterStatementRectorTest */ -final class NewlineAfterStatementRector extends AbstractRector implements HTMLAverseRectorInterface +final class NewlineAfterStatementRector extends AbstractRector { public function __construct( private readonly CommentResolver $commentResolver @@ -74,6 +73,10 @@ public function getNodeTypes(): array */ public function refactor(Node $node): null|Node { + if ($this->getFile()->containsHTML()) { + return null; + } + return $this->processAddNewLine($node, false); } diff --git a/rules/TypeDeclaration/Rector/StmtsAwareInterface/SafeDeclareStrictTypesRector.php b/rules/TypeDeclaration/Rector/StmtsAwareInterface/SafeDeclareStrictTypesRector.php index d5d7f41cbb5..2940293c2c8 100644 --- a/rules/TypeDeclaration/Rector/StmtsAwareInterface/SafeDeclareStrictTypesRector.php +++ b/rules/TypeDeclaration/Rector/StmtsAwareInterface/SafeDeclareStrictTypesRector.php @@ -6,7 +6,6 @@ use PhpParser\Node; use PhpParser\Node\Stmt\Nop; -use Rector\Contract\Rector\HTMLAverseRectorInterface; use Rector\PhpParser\Node\FileNode; use Rector\Rector\AbstractRector; use Rector\RuleDoc\CodeSample\CodeSample; @@ -19,7 +18,7 @@ /** * @see \Rector\Tests\TypeDeclaration\Rector\StmtsAwareInterface\SafeDeclareStrictTypesRector\SafeDeclareStrictTypesRectorTest */ -final class SafeDeclareStrictTypesRector extends AbstractRector implements HTMLAverseRectorInterface, MinPhpVersionInterface +final class SafeDeclareStrictTypesRector extends AbstractRector implements MinPhpVersionInterface { public function __construct( private readonly DeclareStrictTypeFinder $declareStrictTypeFinder, @@ -60,6 +59,10 @@ function acceptsInt(int $value): void */ public function refactor(Node $node): ?FileNode { + if ($this->getFile()->containsHTML()) { + return null; + } + if ($this->declareStrictTypeFinder->hasDeclareStrictTypes($node)) { return null; } diff --git a/src/Application/FileProcessor.php b/src/Application/FileProcessor.php index 48e6a470341..00303a8fc42 100644 --- a/src/Application/FileProcessor.php +++ b/src/Application/FileProcessor.php @@ -60,7 +60,7 @@ public function processFile(File $file, Configuration $configuration): FileProce $fileHasChanged = false; $filePath = $file->getFilePath(); - $currentRectors = $this->rectorRegistry->forFile($file); + $currentRectors = $this->rectorRegistry->getRectors(); $this->rectorNodeTraverser->refreshPhpRectors($currentRectors); do { diff --git a/src/Application/RectorRegistry.php b/src/Application/RectorRegistry.php index 33051dee352..0989c4892d7 100644 --- a/src/Application/RectorRegistry.php +++ b/src/Application/RectorRegistry.php @@ -4,9 +4,7 @@ namespace Rector\Application; -use Rector\Contract\Rector\HTMLAverseRectorInterface; use Rector\Contract\Rector\RectorInterface; -use Rector\ValueObject\Application\File; /** * @see \Rector\Tests\Application\RectorRegistryTest @@ -35,17 +33,8 @@ public function refreshRectors(array $rectors): void /** * @return array */ - public function forFile(File $file): array + public function getRectors(): array { - $rectorsForPath = []; - foreach ($this->rectors as $rector) { - if ($rector instanceof HTMLAverseRectorInterface && $file->containsHTML()) { - continue; - } - - $rectorsForPath[] = $rector; - } - - return $rectorsForPath; + return $this->rectors; } } diff --git a/src/Contract/Rector/HTMLAverseRectorInterface.php b/src/Contract/Rector/HTMLAverseRectorInterface.php deleted file mode 100644 index a456e29647a..00000000000 --- a/src/Contract/Rector/HTMLAverseRectorInterface.php +++ /dev/null @@ -1,13 +0,0 @@ -rectorRegistry->forFile($file); + $rectors = $this->rectorRegistry->getRectors(); - $this->assertCount(1, $rectorsForPath); - $this->assertInstanceOf(FifthElement::class, $rectorsForPath[0]); + $this->assertCount(1, $rectors); + $this->assertInstanceOf(FifthElement::class, $rectors[0]); } }