Page MenuHomePhabricator

Document Article subclasses with different type from Article::newPage in a way phan can understand it
Closed, ResolvedPublic

Description

The ImagePage or CategoryPage class in mediawiki/core are overwritting Article::newPage and returning a different (subclassed) WikiPage object to init $mPage.
Both classes define the $mPage by itself with the proper type, but that extra property is unneeded and dead code.

This is also used in the GlobalUserPage extension, but currently not defining the property with the type,
see https://gerrit.wikimedia.org/r/#/c/mediawiki/extensions/GlobalUserPage/+/511098/ for a discussion.

How to make it correct so static code analyzer like phan can understand that the subclass of WikiPage is always set on $mPage and not a WikiPage?

  • Writing a phan plugin for this
  • Add $mPage as property to sub class
  • @phan-property in a comment near to the real property declaration has not work on my test
  • Override Article::getPage instead, but that also unneeded
  • @phan-method seems only there for magic things, not tested
  • @phan-property on class level comment, not tested
  • ....

To get a overview:
https://codesearch.wmflabs.org/search/?q=function%5Cs%2BnewPage%5Cb&i=nope&files=&repos=

Event Timeline

Yes, I'd say a class-level annotation is the right solution. My only suggestion is to use @property instead of @phan-property: the latter is just an alias, and the former may be useful also for IDEs etc.