diff --git a/build/target-repository/docs/rector_rules_overview.md b/build/target-repository/docs/rector_rules_overview.md
index eef283ea16c..fef5ae24d16 100644
--- a/build/target-repository/docs/rector_rules_overview.md
+++ b/build/target-repository/docs/rector_rules_overview.md
@@ -1,4 +1,4 @@
-# 416 Rules Overview
+# 417 Rules Overview
@@ -12,7 +12,7 @@
- [Compatibility](#compatibility) (1)
-- [DeadCode](#deadcode) (47)
+- [DeadCode](#deadcode) (48)
- [DependencyInjection](#dependencyinjection) (2)
@@ -3664,6 +3664,40 @@ Removes unneeded `$value` = `$value` assigns
+### TargetRemoveClassMethodRector
+
+Remove defined class method
+
+:wrench: **configure it!**
+
+- class: [`Rector\DeadCode\Rector\Class_\TargetRemoveClassMethodRector`](../rules/DeadCode/Rector/Class_/TargetRemoveClassMethodRector.php)
+
+```php
+use Rector\Config\RectorConfig;
+use Rector\DeadCode\Rector\Class_\TargetRemoveClassMethodRector;
+use Rector\DeadCode\ValueObject\TargetRemoveClassMethod;
+
+return static function (RectorConfig $rectorConfig): void {
+ $rectorConfig->ruleWithConfiguration(
+ TargetRemoveClassMethodRector::class,
+ [new TargetRemoveClassMethod('SomeClass', 'run')]
+ );
+};
+```
+
+↓
+
+```diff
+ class SomeClass
+ {
+- public function run()
+- {
+- }
+ }
+```
+
+
+
### TernaryToBooleanOrFalseToBooleanAndRector
Change ternary of bool : false to && bool
diff --git a/rules-tests/DeadCode/Rector/Class_/TargetRemoveClassMethodRector/Fixture/some_class.php.inc b/rules-tests/DeadCode/Rector/Class_/TargetRemoveClassMethodRector/Fixture/some_class.php.inc
new file mode 100644
index 00000000000..a120ea9ff1a
--- /dev/null
+++ b/rules-tests/DeadCode/Rector/Class_/TargetRemoveClassMethodRector/Fixture/some_class.php.inc
@@ -0,0 +1,22 @@
+
+-----
+
diff --git a/rules-tests/Php56/Rector/FunctionLike/AddDefaultValueForUndefinedVariableRector/Php74Test.php b/rules-tests/DeadCode/Rector/Class_/TargetRemoveClassMethodRector/TargetRemoveClassMethodRectorTest.php
similarity index 70%
rename from rules-tests/Php56/Rector/FunctionLike/AddDefaultValueForUndefinedVariableRector/Php74Test.php
rename to rules-tests/DeadCode/Rector/Class_/TargetRemoveClassMethodRector/TargetRemoveClassMethodRectorTest.php
index 83d38d95998..7f10968856c 100644
--- a/rules-tests/Php56/Rector/FunctionLike/AddDefaultValueForUndefinedVariableRector/Php74Test.php
+++ b/rules-tests/DeadCode/Rector/Class_/TargetRemoveClassMethodRector/TargetRemoveClassMethodRectorTest.php
@@ -2,12 +2,12 @@
declare(strict_types=1);
-namespace Rector\Tests\Php56\Rector\FunctionLike\AddDefaultValueForUndefinedVariableRector;
+namespace Rector\Tests\DeadCode\Rector\Class_\TargetRemoveClassMethodRector;
use Iterator;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
-final class Php74Test extends AbstractRectorTestCase
+final class TargetRemoveClassMethodRectorTest extends AbstractRectorTestCase
{
/**
* @dataProvider provideData()
@@ -17,9 +17,12 @@ public function test(string $filePath): void
$this->doTestFile($filePath);
}
+ /**
+ * @return Iterator
+ */
public function provideData(): Iterator
{
- return $this->yieldFilesFromDirectory(__DIR__ . '/FixturePhp74');
+ return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
}
public function provideConfigFilePath(): string
diff --git a/rules-tests/DeadCode/Rector/Class_/TargetRemoveClassMethodRector/config/configured_rule.php b/rules-tests/DeadCode/Rector/Class_/TargetRemoveClassMethodRector/config/configured_rule.php
new file mode 100644
index 00000000000..09af0d560db
--- /dev/null
+++ b/rules-tests/DeadCode/Rector/Class_/TargetRemoveClassMethodRector/config/configured_rule.php
@@ -0,0 +1,16 @@
+ruleWithConfiguration(TargetRemoveClassMethodRector::class, [
+ new TargetRemoveClassMethod(
+ 'Rector\Tests\DeadCode\Rector\Class_\TargetRemoveClassMethodRector\Fixture\SomeClass',
+ 'removeMe'
+ ),
+ ]);
+};
diff --git a/rules-tests/Php56/Rector/FunctionLike/AddDefaultValueForUndefinedVariableRector/FixturePhp74/arrow_function.php.inc b/rules-tests/Php56/Rector/FunctionLike/AddDefaultValueForUndefinedVariableRector/Fixture/arrow_function.php.inc
similarity index 81%
rename from rules-tests/Php56/Rector/FunctionLike/AddDefaultValueForUndefinedVariableRector/FixturePhp74/arrow_function.php.inc
rename to rules-tests/Php56/Rector/FunctionLike/AddDefaultValueForUndefinedVariableRector/Fixture/arrow_function.php.inc
index 3395a365ad3..b00d2c7406b 100644
--- a/rules-tests/Php56/Rector/FunctionLike/AddDefaultValueForUndefinedVariableRector/FixturePhp74/arrow_function.php.inc
+++ b/rules-tests/Php56/Rector/FunctionLike/AddDefaultValueForUndefinedVariableRector/Fixture/arrow_function.php.inc
@@ -1,6 +1,6 @@
isAnonymous()) {
+ return null;
+ }
+
+ foreach ($this->targetRemoveClassMethods as $targetRemoveClassMethod) {
+ if (! $this->isName($node, $targetRemoveClassMethod->getClassName())) {
+ continue;
+ }
+
+ $classMethod = $node->getMethod($targetRemoveClassMethod->getMethodName());
+ if (! $classMethod instanceof ClassMethod) {
+ continue;
+ }
+
+ $this->removeNode($classMethod);
+ return null;
+ }
+
+ return null;
+ }
+
+ /**
+ * @param mixed[] $configuration
+ */
+ public function configure(array $configuration): void
+ {
+ Assert::notEmpty($configuration);
+ Assert::allIsInstanceOf($configuration, TargetRemoveClassMethod::class);
+
+ $this->targetRemoveClassMethods = $configuration;
+ }
+}
diff --git a/rules/DeadCode/ValueObject/TargetRemoveClassMethod.php b/rules/DeadCode/ValueObject/TargetRemoveClassMethod.php
new file mode 100644
index 00000000000..b7b8dfa3af3
--- /dev/null
+++ b/rules/DeadCode/ValueObject/TargetRemoveClassMethod.php
@@ -0,0 +1,24 @@
+className;
+ }
+
+ public function getMethodName(): string
+ {
+ return $this->methodName;
+ }
+}