Page MenuHomePhabricator

CoreParserHooks/CoreParserFunctions/CoreMagicWords have too many static functions
Open, Needs TriagePublic

Description

As @thiemowmde says in https://gerrit.wikimedia.org/r/583752 :

I wish we could avoid static code if possible. It's so much harder to write tests when static code is involved. It's impossible to mock. Which means it's not possible to write pure unit tests for code that calls static code. You will always end testing the static code together with what you want to test.

Unfortunately, CoreParserHooks and CoreParserFunctions (and the newly refactored CoreMagicWords) all have this same too-many-static-functions pattern.

They should be refactored. As a start, CoreParserHooks and CoreParserFunctions could keep their existing static register method, but that method could construct a CoreParserFunctions object and then register its methods, instead of directly registering static methods of the class.