Merge "UserFactory: Simplify and type hint newAnonymous"

This commit is contained in:
jenkins-bot 2021-08-18 00:16:42 +00:00 committed by Gerrit Code Review
commit 48a3b2e7f8

View file

@ -109,14 +109,12 @@ class UserFactory implements IDBAccessObject, UserRigorOptions {
* @param string|null $ip IP address
* @return User
*/
public function newAnonymous( $ip = null ): User {
public function newAnonymous( ?string $ip = null ): User {
if ( $ip ) {
$validIp = $this->userNameUtils->isIP( $ip );
if ( $validIp ) {
$user = $this->newFromName( $ip, self::RIGOR_NONE );
} else {
if ( !$this->userNameUtils->isIP( $ip ) ) {
throw new InvalidArgumentException( 'Invalid IP address' );
}
$user = $this->newFromName( $ip, self::RIGOR_NONE );
} else {
$user = new User();
}