rectorphp / rector-symfony

Rector upgrade rules for Symfony
http://getrector.com
MIT License
179 stars 86 forks source link

#[AsMessageHandler] on abstract classes produces untagged services #655

Open possi opened 1 month ago

possi commented 1 month ago

Example:

abstract class AbstractHandler implements MessageHandlerInterface {

}
class ExampleHandler extends AbstractHandler {
  // ...
}

Thanks to symfony-frameworks registerForAutoconfiguration the ExampleHandler is tagged as messenger.message_handler, as the class (indirect) implements the interface.


Result after rector:

#[AsMessageHandler]
abstract class AbstractHandler {
  // ...
}
class ExampleHandler extends AbstractHandler {
  // ...
}

No service gets tagged:


Possible solution:

I would recommend to add final to all modified classes. This prevents extending a message handler service and expecting to automaticly get tagged. Any wrong usages are instantly visible. Just skipping abstract classes wouldn't be sufficient, as some may also extend a non abstract service.