My refactoring book says things like "static methods are death to testability".
I assume that PageTriage's 93 PHP static methods should be refactored to non-static and dependency injected.
Thoughts?
Novem_Linguae | |
Nov 30 2022, 6:19 AM |
F35824967: image.png | |
Nov 30 2022, 6:19 AM |
My refactoring book says things like "static methods are death to testability".
I assume that PageTriage's 93 PHP static methods should be refactored to non-static and dependency injected.
Thoughts?
Status | Subtype | Assigned | Task | ||
---|---|---|---|---|---|
Open | None | T324211 Refactor PageTriage to use services with narrow scopes and value objects for passing data | |||
Open | None | T324070 Refactor PageTriage static methods to be non-static |
I'd say the answer is "it depends".
Some of those static methods can be resolved with T323908: Refactor Hooks.php to use HookHandlers but that doesn't in itself guarantee any testability; you'd still need to convert the hooks to use dependency injection, and write the tests.
You could, currently, call the static methods from those hooks and mock various services and override the services by using MediaWikiIntegrationTestCase::overrideMwServices().
In general, splitting up classes according to single responsibility principle would naturally lead to more class based methods and fewer static classes. I'm not sure that needs to be tracked in a task, though. (I left some comments here as well T324072#8431022 for refactoring ideas.)
I like the task because it gets the conversation started and gets us on the same page about strategy. Thanks for your insights :)