diff --git a/rules-tests/CodingStyle/Rector/Stmt/NewlineAfterStatementRector/Fixture/complex_if.php.inc b/rules-tests/CodingStyle/Rector/Stmt/NewlineAfterStatementRector/Fixture/complex_if.php.inc
deleted file mode 100644
index ce5289247af..00000000000
--- a/rules-tests/CodingStyle/Rector/Stmt/NewlineAfterStatementRector/Fixture/complex_if.php.inc
+++ /dev/null
@@ -1,78 +0,0 @@
-
------
-
diff --git a/rules-tests/CodingStyle/Rector/Stmt/NewlineAfterStatementRector/Fixture/complex_try_catch.php.inc b/rules-tests/CodingStyle/Rector/Stmt/NewlineAfterStatementRector/Fixture/complex_try_catch.php.inc
deleted file mode 100644
index c143070a35c..00000000000
--- a/rules-tests/CodingStyle/Rector/Stmt/NewlineAfterStatementRector/Fixture/complex_try_catch.php.inc
+++ /dev/null
@@ -1,50 +0,0 @@
-
------
-
diff --git a/rules-tests/CodingStyle/Rector/Stmt/NewlineAfterStatementRector/Fixture/no_new_line.php.inc b/rules-tests/CodingStyle/Rector/Stmt/NewlineAfterStatementRector/Fixture/no_new_line.php.inc
deleted file mode 100644
index 1ab28344fff..00000000000
--- a/rules-tests/CodingStyle/Rector/Stmt/NewlineAfterStatementRector/Fixture/no_new_line.php.inc
+++ /dev/null
@@ -1,45 +0,0 @@
- $value) {
- # code...
- }
- return true;
- }
-}
-
-?>
------
- $value) {
- # code...
- }
-
- return true;
- }
-}
-
-?>
diff --git a/rules-tests/CodingStyle/Rector/Stmt/NewlineAfterStatementRector/Fixture/no_new_line_classlike.php.inc b/rules-tests/CodingStyle/Rector/Stmt/NewlineAfterStatementRector/Fixture/no_new_line_classlike.php.inc
deleted file mode 100644
index 01b470d03f3..00000000000
--- a/rules-tests/CodingStyle/Rector/Stmt/NewlineAfterStatementRector/Fixture/no_new_line_classlike.php.inc
+++ /dev/null
@@ -1,56 +0,0 @@
-
------
-
diff --git a/rules-tests/CodingStyle/Rector/Stmt/NewlineAfterStatementRector/Fixture/no_new_line_function.php.inc b/rules-tests/CodingStyle/Rector/Stmt/NewlineAfterStatementRector/Fixture/no_new_line_function.php.inc
deleted file mode 100644
index 994a7057a99..00000000000
--- a/rules-tests/CodingStyle/Rector/Stmt/NewlineAfterStatementRector/Fixture/no_new_line_function.php.inc
+++ /dev/null
@@ -1,26 +0,0 @@
-
------
-
diff --git a/rules-tests/CodingStyle/Rector/Stmt/NewlineAfterStatementRector/Fixture/no_new_line_switch.php.inc b/rules-tests/CodingStyle/Rector/Stmt/NewlineAfterStatementRector/Fixture/no_new_line_switch.php.inc
deleted file mode 100644
index 9f650fa918a..00000000000
--- a/rules-tests/CodingStyle/Rector/Stmt/NewlineAfterStatementRector/Fixture/no_new_line_switch.php.inc
+++ /dev/null
@@ -1,36 +0,0 @@
-
------
-
diff --git a/rules-tests/CodingStyle/Rector/Stmt/NewlineAfterStatementRector/Fixture/no_new_line_try_catch.php.inc b/rules-tests/CodingStyle/Rector/Stmt/NewlineAfterStatementRector/Fixture/no_new_line_try_catch.php.inc
deleted file mode 100644
index e74652b0403..00000000000
--- a/rules-tests/CodingStyle/Rector/Stmt/NewlineAfterStatementRector/Fixture/no_new_line_try_catch.php.inc
+++ /dev/null
@@ -1,32 +0,0 @@
-
------
-
diff --git a/rules-tests/CodingStyle/Rector/Stmt/NewlineAfterStatementRector/Fixture/skip_already_has_newline.php.inc b/rules-tests/CodingStyle/Rector/Stmt/NewlineAfterStatementRector/Fixture/skip_already_has_newline.php.inc
deleted file mode 100644
index bd26fe3cd84..00000000000
--- a/rules-tests/CodingStyle/Rector/Stmt/NewlineAfterStatementRector/Fixture/skip_already_has_newline.php.inc
+++ /dev/null
@@ -1,21 +0,0 @@
- $value) {
- # code...
- }
-
- return true;
- }
-}
diff --git a/rules-tests/CodingStyle/Rector/Stmt/NewlineAfterStatementRector/Fixture/skip_class_like.php.inc b/rules-tests/CodingStyle/Rector/Stmt/NewlineAfterStatementRector/Fixture/skip_class_like.php.inc
deleted file mode 100644
index 86f3b823a50..00000000000
--- a/rules-tests/CodingStyle/Rector/Stmt/NewlineAfterStatementRector/Fixture/skip_class_like.php.inc
+++ /dev/null
@@ -1,13 +0,0 @@
-
-
-
Hi
-
-
-
-
-
Bye
-
-
-
-
-End of file
diff --git a/rules-tests/CodingStyle/Rector/Stmt/NewlineAfterStatementRector/Fixture/skip_if_inside_do_while_next_not_stmt.php.inc b/rules-tests/CodingStyle/Rector/Stmt/NewlineAfterStatementRector/Fixture/skip_if_inside_do_while_next_not_stmt.php.inc
deleted file mode 100644
index 1f016ab9509..00000000000
--- a/rules-tests/CodingStyle/Rector/Stmt/NewlineAfterStatementRector/Fixture/skip_if_inside_do_while_next_not_stmt.php.inc
+++ /dev/null
@@ -1,15 +0,0 @@
-foo);
- }
-}
diff --git a/rules-tests/CodingStyle/Rector/Stmt/NewlineAfterStatementRector/Fixture/skip_inside_return_statement.php.inc b/rules-tests/CodingStyle/Rector/Stmt/NewlineAfterStatementRector/Fixture/skip_inside_return_statement.php.inc
deleted file mode 100644
index 761261f781d..00000000000
--- a/rules-tests/CodingStyle/Rector/Stmt/NewlineAfterStatementRector/Fixture/skip_inside_return_statement.php.inc
+++ /dev/null
@@ -1,16 +0,0 @@
-doTestFile($filePath);
- }
-
- public static function provideData(): Iterator
- {
- return self::yieldFilesFromDirectory(__DIR__ . '/Fixture');
- }
-
- public function provideConfigFilePath(): string
- {
- return __DIR__ . '/config/configured_rule.php';
- }
-}
diff --git a/rules-tests/CodingStyle/Rector/Stmt/NewlineAfterStatementRector/config/configured_rule.php b/rules-tests/CodingStyle/Rector/Stmt/NewlineAfterStatementRector/config/configured_rule.php
deleted file mode 100644
index 414e8d43049..00000000000
--- a/rules-tests/CodingStyle/Rector/Stmt/NewlineAfterStatementRector/config/configured_rule.php
+++ /dev/null
@@ -1,9 +0,0 @@
-withRules([NewlineAfterStatementRector::class]);
diff --git a/rules/CodingStyle/Rector/Stmt/NewlineAfterStatementRector.php b/rules/CodingStyle/Rector/Stmt/NewlineAfterStatementRector.php
index 98d53c457db..8346ad48545 100644
--- a/rules/CodingStyle/Rector/Stmt/NewlineAfterStatementRector.php
+++ b/rules/CodingStyle/Rector/Stmt/NewlineAfterStatementRector.php
@@ -5,24 +5,18 @@
namespace Rector\CodingStyle\Rector\Stmt;
use PhpParser\Node;
-use PhpParser\Node\Stmt;
-use PhpParser\Node\Stmt\Nop;
-use Rector\Comments\CommentResolver;
+use Rector\Configuration\Deprecation\Contract\DeprecatedInterface;
+use Rector\Exception\ShouldNotHappenException;
use Rector\PhpParser\Enum\NodeGroup;
use Rector\Rector\AbstractRector;
use Rector\RuleDoc\CodeSample\CodeSample;
use Rector\RuleDoc\RuleDefinition;
/**
- * @see \Rector\Tests\CodingStyle\Rector\Stmt\NewlineAfterStatementRector\NewlineAfterStatementRectorTest
+ * @deprecated This rule is deprecated, as newlines between statements are coding standard concern and its definition is too vague. Use coding standard tool like ECS or PHP CS Fixer instead.
*/
-final class NewlineAfterStatementRector extends AbstractRector
+final class NewlineAfterStatementRector extends AbstractRector implements DeprecatedInterface
{
- public function __construct(
- private readonly CommentResolver $commentResolver
- ) {
- }
-
public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition(
@@ -67,71 +61,11 @@ public function getNodeTypes(): array
return NodeGroup::STMTS_AWARE;
}
- /**
- * @param StmtsAware $node
- * @return StmtsAware|null
- */
- public function refactor(Node $node): null|Node
- {
- if ($this->getFile()->containsHTML()) {
- return null;
- }
-
- return $this->processAddNewLine($node, false);
- }
-
- /**
- * @param StmtsAware $node
- * @return StmtsAware|null
- */
- private function processAddNewLine(Node $node, bool $hasChanged, int $jumpToKey = 0): null|Node
- {
- if ($node->stmts === null) {
- return null;
- }
-
- $totalKeys = array_key_last($node->stmts);
-
- for ($key = $jumpToKey; $key < $totalKeys; ++$key) {
- if (! isset($node->stmts[$key], $node->stmts[$key + 1])) {
- break;
- }
-
- $stmt = $node->stmts[$key];
- $nextStmt = $node->stmts[$key + 1];
-
- if ($this->shouldSkip($stmt)) {
- continue;
- }
-
- /** @var Stmt $stmt */
- $endLine = $stmt->getEndLine();
- $rangeLine = $nextStmt->getStartLine() - $endLine;
-
- if ($rangeLine > 1) {
- $rangeLine = $this->commentResolver->resolveRangeLineFromComment($rangeLine, $endLine, $nextStmt);
- }
-
- // skip same line or < 0 that cause infinite loop or crash
- if ($rangeLine !== 1) {
- continue;
- }
-
- array_splice($node->stmts, $key + 1, 0, [new Nop()]);
-
- $hasChanged = true;
- return $this->processAddNewLine($node, $hasChanged, $key + 2);
- }
-
- if ($hasChanged) {
- return $node;
- }
-
- return null;
- }
-
- private function shouldSkip(Stmt $stmt): bool
+ public function refactor(Node $node): ?Node
{
- return ! in_array($stmt::class, NodeGroup::STMTS_TO_HAVE_NEXT_NEWLINE, true);
+ throw new ShouldNotHappenException(sprintf(
+ '"%s" rule is deprecated, as newlines between statements are coding standard concern; use coding standard tool like ECS or PHP CS Fixer instead',
+ self::class
+ ));
}
}
diff --git a/src/Config/Level/CodingStyleLevel.php b/src/Config/Level/CodingStyleLevel.php
index 32e262da50a..52cbadf942b 100644
--- a/src/Config/Level/CodingStyleLevel.php
+++ b/src/Config/Level/CodingStyleLevel.php
@@ -19,7 +19,6 @@
use Rector\CodingStyle\Rector\FuncCall\VersionCompareFuncCallToConstantRector;
use Rector\CodingStyle\Rector\If_\AlternativeIfToBracketRector;
use Rector\CodingStyle\Rector\Property\SplitGroupedPropertiesRector;
-use Rector\CodingStyle\Rector\Stmt\NewlineAfterStatementRector;
use Rector\CodingStyle\Rector\Stmt\RemoveUselessAliasInUseStatementRector;
use Rector\CodingStyle\Rector\String_\SimplifyQuoteEscapeRector;
use Rector\CodingStyle\Rector\String_\UseClassKeywordForClassNameResolutionRector;
@@ -49,7 +48,6 @@ final class CodingStyleLevel
public const array RULES = [
SeparateMultiUseImportsRector::class,
NewlineBetweenClassLikeStmtsRector::class,
- NewlineAfterStatementRector::class,
AlternativeIfToBracketRector::class,
CompleteMissingIfElseBracketRector::class,
SimplifyQuoteEscapeRector::class,
diff --git a/src/PhpParser/Enum/NodeGroup.php b/src/PhpParser/Enum/NodeGroup.php
index b9d63a419ec..0ec814c107e 100644
--- a/src/PhpParser/Enum/NodeGroup.php
+++ b/src/PhpParser/Enum/NodeGroup.php
@@ -9,8 +9,6 @@
use PhpParser\Node\Stmt\Block;
use PhpParser\Node\Stmt\Case_;
use PhpParser\Node\Stmt\Catch_;
-use PhpParser\Node\Stmt\Class_;
-use PhpParser\Node\Stmt\ClassConst;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Declare_;
use PhpParser\Node\Stmt\Do_;
@@ -21,11 +19,7 @@
use PhpParser\Node\Stmt\Foreach_;
use PhpParser\Node\Stmt\Function_;
use PhpParser\Node\Stmt\If_;
-use PhpParser\Node\Stmt\Interface_;
use PhpParser\Node\Stmt\Namespace_;
-use PhpParser\Node\Stmt\Property;
-use PhpParser\Node\Stmt\Switch_;
-use PhpParser\Node\Stmt\Trait_;
use PhpParser\Node\Stmt\TryCatch;
use PhpParser\Node\Stmt\While_;
use Rector\PhpParser\Node\FileNode;
@@ -60,26 +54,6 @@ final class NodeGroup
Declare_::class,
];
- /**
- * @var array>
- */
- public const array STMTS_TO_HAVE_NEXT_NEWLINE = [
- ClassMethod::class,
- Function_::class,
- Property::class,
- If_::class,
- Foreach_::class,
- Do_::class,
- While_::class,
- For_::class,
- ClassConst::class,
- TryCatch::class,
- Class_::class,
- Trait_::class,
- Interface_::class,
- Switch_::class,
- ];
-
public static function isStmtAwareNode(Node $node): bool
{
// native instanceof instead of array_any() over STMTS_AWARE - avoids the per-element
diff --git a/tests/Issues/IndentationCrash/config/code_quality_coding_style_configured_rule.php b/tests/Issues/IndentationCrash/config/code_quality_coding_style_configured_rule.php
index d34d07d60ef..2ce2d330aa4 100644
--- a/tests/Issues/IndentationCrash/config/code_quality_coding_style_configured_rule.php
+++ b/tests/Issues/IndentationCrash/config/code_quality_coding_style_configured_rule.php
@@ -3,7 +3,6 @@
declare(strict_types=1);
use Rector\CodeQuality\Rector\If_\SimplifyIfReturnBoolRector;
-use Rector\CodingStyle\Rector\Stmt\NewlineAfterStatementRector;
use Rector\Config\RectorConfig;
use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector;
@@ -11,7 +10,6 @@
->withRules(
[
SimplifyIfReturnBoolRector::class,
- NewlineAfterStatementRector::class,
StringClassNameToClassConstantRector::class,
]
);
diff --git a/tests/Issues/Issue6840/ClassPropertyPromotionAndNewLineAfterStatementRectorTest.php b/tests/Issues/Issue6840/ClassPropertyPromotionAndNewLineAfterStatementRectorTest.php
deleted file mode 100644
index 624221fb049..00000000000
--- a/tests/Issues/Issue6840/ClassPropertyPromotionAndNewLineAfterStatementRectorTest.php
+++ /dev/null
@@ -1,31 +0,0 @@
-doTestFile($filePath);
- }
-
- public static function provideData(): Iterator
- {
- return self::yieldFilesFromDirectory(__DIR__ . '/Fixture');
- }
-
- public function provideConfigFilePath(): string
- {
- return __DIR__ . '/config/configured_rule.php';
- }
-}
diff --git a/tests/Issues/Issue6840/Fixture/fixture.php.inc b/tests/Issues/Issue6840/Fixture/fixture.php.inc
deleted file mode 100644
index 2354e4b656c..00000000000
--- a/tests/Issues/Issue6840/Fixture/fixture.php.inc
+++ /dev/null
@@ -1,31 +0,0 @@
-imageId = $imageId;
- $this->imageSize = [];
- }
-}
-?>
------
-imageSize = [];
- }
-}
-?>
diff --git a/tests/Issues/Issue6840/config/configured_rule.php b/tests/Issues/Issue6840/config/configured_rule.php
deleted file mode 100644
index 260da73479f..00000000000
--- a/tests/Issues/Issue6840/config/configured_rule.php
+++ /dev/null
@@ -1,10 +0,0 @@
-withRules([ClassPropertyAssignToConstructorPromotionRector::class, NewlineAfterStatementRector::class]);