Page MenuHomePhabricator

Refactor PageTriage static methods to be non-static
Open, Needs TriagePublic

Description

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?

image.png (1×625 px, 134 KB)

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript

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 :)

HouseBlaster renamed this task from Refactor static methods to be non-static to Refactor PageTriage static methods to be non-static.Dec 3 2022, 12:39 AM
HouseBlaster moved this task from Unsorted to Needs refactor on the Technical-Debt board.