Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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';

Expand Down Expand Up @@ -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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
{
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@
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;

/**
* @see \Rector\Tests\CodingStyle\Rector\ClassMethod\NewlineBeforeNewAssignSetRector\NewlineBeforeNewAssignSetRectorTest
*/
final class NewlineBeforeNewAssignSetRector extends AbstractRector implements HTMLAverseRectorInterface
final class NewlineBeforeNewAssignSetRector extends AbstractRector
{
private ?string $previousStmtVariableName = null;

Expand Down Expand Up @@ -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;
Expand Down
7 changes: 5 additions & 2 deletions rules/CodingStyle/Rector/If_/AlternativeIfToBracketRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
{
Expand Down Expand Up @@ -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;
}
Expand Down
7 changes: 5 additions & 2 deletions rules/CodingStyle/Rector/Stmt/NewlineAfterStatementRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Application/FileProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
15 changes: 2 additions & 13 deletions src/Application/RectorRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -35,17 +33,8 @@ public function refreshRectors(array $rectors): void
/**
* @return array<RectorInterface>
*/
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;
}
}
13 changes: 0 additions & 13 deletions src/Contract/Rector/HTMLAverseRectorInterface.php

This file was deleted.

10 changes: 4 additions & 6 deletions tests/Application/RectorRegistryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use Rector\Configuration\Parameter\SimpleParameterProvider;
use Rector\Testing\PHPUnit\AbstractLazyTestCase;
use Rector\Tests\Skipper\Skipper\Fixture\Element\FifthElement;
use Rector\ValueObject\Application\File;

final class RectorRegistryTest extends AbstractLazyTestCase
{
Expand All @@ -32,12 +31,11 @@ protected function tearDown(): void
SimpleParameterProvider::setParameter(Option::SKIP, []);
}

public function testForFile(): void
public function testGetRectors(): void
{
$file = new File(__DIR__ . '/some_file.php', '');
$rectorsForPath = $this->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]);
}
}
Loading