diff --git a/rules-tests/DeadCode/Rector/ClassMethod/RemoveUnusedPublicMethodParameterRector/Fixture/skip_command_handler.php.inc b/rules-tests/DeadCode/Rector/ClassMethod/RemoveUnusedPublicMethodParameterRector/Fixture/skip_command_handler.php.inc new file mode 100644 index 00000000000..54f98ff667f --- /dev/null +++ b/rules-tests/DeadCode/Rector/ClassMethod/RemoveUnusedPublicMethodParameterRector/Fixture/skip_command_handler.php.inc @@ -0,0 +1,13 @@ +isFinal() || $node->extends instanceof FullyQualified || $node->implements !== []) { return null; } $hasChanged = false; foreach ($node->getMethods() as $classMethod) { - if (! $classMethod->isPublic()) { - continue; - } - - if ($classMethod->params === []) { - continue; - } - - if ($this->magicClassMethodAnalyzer->isUnsafeOverridden($classMethod)) { - continue; - } - - if ($this->variadicFunctionLikeDetector->isVariadic($classMethod)) { + if ($this->shouldSkipClassMethod($classMethod, $node)) { continue; } @@ -109,4 +99,30 @@ public function refactor(Node $node): ?Node return null; } + + private function shouldSkipClassMethod(ClassMethod $classMethod, Class_ $class): bool + { + // private method is handled by different rule + if (! $classMethod->isPublic()) { + return true; + } + + if ($classMethod->params === []) { + return true; + } + + // parameter is required for contract coupling + if ($this->isName($classMethod->name, '__invoke') && $this->phpAttributeAnalyzer->hasPhpAttribute( + $class, + 'Symfony\Component\Messenger\Attribute\AsMessageHandler' + )) { + return true; + } + + if ($this->magicClassMethodAnalyzer->isUnsafeOverridden($classMethod)) { + return true; + } + + return $this->variadicFunctionLikeDetector->isVariadic($classMethod); + } }