While working on refactoring how AbuseFilter triggers Echo notification, I noticed that AbuseFilter heavily operates on $userId and $userName pairs instead of using UserIdentity.
The LasteditInfo class keeps the User information as two separate variables ($userId and $userName). We should use the UserIdentity instead to ensure that these two are always updated together, as they represent one entity.
Core migrates away from using ints to pass Users, more components require UserIdentity as a user representation. (example Linker::userLink( $userId, $userName ... ) is deprecated in favour of UserLinkRenderer::userLink( UserIdentity $targetUser ...) .
How to Refactor:
Instead of expecting and passing around
/** * @param int $userID * @param string $userName * @param string $timestamp */ public function __construct( int $userID, string $userName, string $timestamp ) { $this->userID = $userID; $this->userName = $userName; $this->timestamp = $timestamp; }
We should depend on UserIdentity:
/** * @param UserIdentity $identity * @param string $timestamp */ public function __construct( UserIdentity $identity, string $timestamp ) { $this->identity = $identity; $this->timestamp = $timestamp; }
The callers should retrieve user information by calling $editInfo->getUserIdentity() instead of operating on getUserId() and getUserName().
Note: User object already implements UserIdentity, therefore it will be enough just to pass the user. And when working on raw database results
it should be enough to call UserIdentityValue::newRegistered() to get a UserIdentity based on the userId and userName.