The method has a weird signature:
public static function userLink( $userId, $userName, $altUserName = false ) {
which requires the caller to pass the ID and name separately. Additionally, the case with ID==0 can be used to link to external users (via ExternalUserNames). In fact, the ID is only used to detect anons and external users.
Instead, I believe that the function should simply accept a UserIdentity object, to derive the name, whether the user is anonymous, and whether it's external (with getWikiId()). I also wonder whether the method should be moved to LinkRenderer, or perhaps a new service.