Page MenuHomePhabricator

Phan cannot find classes after namespace move
Closed, ResolvedPublic

Description

In Ie808d49aed, as part of T172368: Make the Wikibase.git code base PSR-4 compatible, I moved some classes in Wikibase to a more appropriate namespace. Some of them are used in other extensions as well, so for those I added a class_alias with the old name so that the extensions wouldn’t break until they’d been updated for the move. However, phan still fails when analyzing those extensions (console):

<?xml version="1.0" encoding="ISO-8859-15"?>
<checkstyle version="6.5">
  <file name="WikibaseLexeme.datatypes.php">
    <error line="46" severity="error" message="Call to method __construct from undeclared class \Wikibase\Lib\SnakFormat (Did you mean class \Wikibase\Lib\Formatters\SnakFormat)" source="PhanUndeclaredClassMethod"/>
    <error line="48" severity="error" message="Reference to constant FORMAT_HTML from undeclared class \Wikibase\Lib\SnakFormatter (Did you mean interface \Wikibase\Lib\Formatters\SnakFormatter)" source="PhanUndeclaredClassConstant"/>
    <error line="48" severity="error" message="Call to method getBaseFormat from undeclared class \Wikibase\Lib\SnakFormat (Did you mean class \Wikibase\Lib\Formatters\SnakFormat)" source="PhanUndeclaredClassMethod"/>
    <error line="59" severity="error" message="Call to method __construct from undeclared class \Wikibase\Lib\EntityIdValueFormatter (Did you mean class \Wikibase\Lib\Formatters\EntityIdValueFormatter)" source="PhanUndeclaredClassMethod"/>
    <error line="85" severity="error" message="Call to method __construct from undeclared class \Wikibase\Lib\SnakFormat (Did you mean class \Wikibase\Lib\Formatters\SnakFormat)" source="PhanUndeclaredClassMethod"/>
    <error line="87" severity="error" message="Reference to constant FORMAT_HTML from undeclared class \Wikibase\Lib\SnakFormatter (Did you mean interface \Wikibase\Lib\Formatters\SnakFormatter)" source="PhanUndeclaredClassConstant"/>
    <error line="87" severity="error" message="Call to method getBaseFormat from undeclared class \Wikibase\Lib\SnakFormat (Did you mean class \Wikibase\Lib\Formatters\SnakFormat)" source="PhanUndeclaredClassMethod"/>
    <error line="104" severity="error" message="Call to method __construct from undeclared class \Wikibase\Lib\EntityIdValueFormatter (Did you mean class \Wikibase\Lib\Formatters\EntityIdValueFormatter)" source="PhanUndeclaredClassMethod"/>
    <error line="125" severity="error" message="Call to method __construct from undeclared class \Wikibase\Lib\SnakFormat (Did you mean class \Wikibase\Lib\Formatters\SnakFormat)" source="PhanUndeclaredClassMethod"/>
    <error line="127" severity="error" message="Reference to constant FORMAT_HTML from undeclared class \Wikibase\Lib\SnakFormatter (Did you mean interface \Wikibase\Lib\Formatters\SnakFormatter)" source="PhanUndeclaredClassConstant"/>
    <error line="127" severity="error" message="Call to method getBaseFormat from undeclared class \Wikibase\Lib\SnakFormat (Did you mean class \Wikibase\Lib\Formatters\SnakFormat)" source="PhanUndeclaredClassMethod"/>
    <error line="130" severity="error" message="Call to method __construct from undeclared class \Wikibase\Lib\EntityIdValueFormatter (Did you mean class \Wikibase\Lib\Formatters\EntityIdValueFormatter)" source="PhanUndeclaredClassMethod"/>
    <error line="141" severity="error" message="Call to method __construct from undeclared class \Wikibase\Lib\EntityIdValueFormatter (Did you mean class \Wikibase\Lib\Formatters\EntityIdValueFormatter)" source="PhanUndeclaredClassMethod"/>
  </file>
  <file name="src/Presentation/Formatters/FormIdHtmlFormatter.php">
    <error line="40" severity="warning" message="Property \Wikibase\Lexeme\Presentation\Formatters\FormIdHtmlFormatter-&amp;gt;nonExistingIdFormatter has undeclared type \Wikibase\Lib\NonExistingEntityIdHtmlFormatter (Did you mean class \Wikibase\Lib\Formatters\NonExistingEntityIdHtmlFormatter)" source="PhanUndeclaredTypeProperty"/>
    <error line="69" severity="error" message="Call to method __construct from undeclared class \Wikibase\Lib\NonExistingEntityIdHtmlFormatter (Did you mean class \Wikibase\Lib\Formatters\NonExistingEntityIdHtmlFormatter)" source="PhanUndeclaredClassMethod"/>
    <error line="88" severity="error" message="Call to method formatEntityId from undeclared class \Wikibase\Lib\NonExistingEntityIdHtmlFormatter (Did you mean class \Wikibase\Lib\Formatters\NonExistingEntityIdHtmlFormatter)" source="PhanUndeclaredClassMethod"/>
  </file>
</checkstyle>

Does anyone know why that is? In this case, the problem should resolve itself soon (I uploaded patches for all the affected extensions and they’re all +2ed already), but in general it would be concerning if we couldn’t move classes between namespaces even with compatibility aliases.

Event Timeline

Mediawiki-phan 0.6.1 added phan support for class_alias, but wikibase isn't included because for some reason it has its own phan config file, instead of requiring the base one.

And for that I sent https://gerrit.wikimedia.org/r/#/c/mediawiki/extensions/Wikibase/+/518287/ If you're interested in reviewing. It's big, but trivial.

Change 518256 had a related patch set uploaded (by Daimona Eaytoy; owner: Daimona Eaytoy):
[mediawiki/extensions/WikibaseLexeme@master] [WIP] Update phan, cleanup config

https://gerrit.wikimedia.org/r/518256

Change 518256 merged by jenkins-bot:
[mediawiki/extensions/WikibaseLexeme@master] Update phan, cleanup config

https://gerrit.wikimedia.org/r/518256

WBLexeme is now importing the base config which supports class_alias.