Implementations of Entity::setId() should require an EntityId as a parameter. At present, they also support int parameters, and then create the appropriate EntityId internally. Besides this being a nasty B/C hack, it does not work for foreign IDs.
Support for numeric IDs can be removed from Entity::setId() by making all callers that use an integer construct an EntityId first, using the EntityIdComposer service. In particular, this is the case for WikiPageEntityStore::assignFreshId().