diff --git a/packages/DeadCode/src/Rector/ClassMethod/RemoveUnusedParameterRector.php b/packages/DeadCode/src/Rector/ClassMethod/RemoveUnusedParameterRector.php index d2a4fefc84e7..29206648317b 100644 --- a/packages/DeadCode/src/Rector/ClassMethod/RemoveUnusedParameterRector.php +++ b/packages/DeadCode/src/Rector/ClassMethod/RemoveUnusedParameterRector.php @@ -28,6 +28,26 @@ final class RemoveUnusedParameterRector extends AbstractRector */ private $classMethodManipulator; + /** + * @var string[] + */ + private $magicMethods = [ + '__call', + '__callStatic', + '__clone', + '__debugInfo', + '__destruct', + '__get', + '__invoke', + '__isset', + '__set', + '__set_state', + '__sleep', + '__toString', + '__unset', + '__wakeup', + ]; + public function __construct(ClassManipulator $classManipulator, ClassMethodManipulator $classMethodManipulator) { $this->classManipulator = $classManipulator; @@ -83,6 +103,10 @@ public function refactor(Node $node): ?Node return null; } + if ($this->isNames($node, $this->magicMethods)) { + return null; + } + $class = $this->getName($classNode); if ($class === null) { return null; diff --git a/packages/DeadCode/tests/Rector/ClassMethod/RemoveUnusedParameterRector/Fixture/keep_magic_methods_param.php.inc b/packages/DeadCode/tests/Rector/ClassMethod/RemoveUnusedParameterRector/Fixture/keep_magic_methods_param.php.inc new file mode 100644 index 000000000000..9e9ad2e7141b --- /dev/null +++ b/packages/DeadCode/tests/Rector/ClassMethod/RemoveUnusedParameterRector/Fixture/keep_magic_methods_param.php.inc @@ -0,0 +1,26 @@ +