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 * @param string|null $ip IP address
* @return User * @return User
*/ */
public function newAnonymous( $ip = null ): User { public function newAnonymous( ?string $ip = null ): User {
if ( $ip ) { if ( $ip ) {
$validIp = $this->userNameUtils->isIP( $ip ); if ( !$this->userNameUtils->isIP( $ip ) ) {
if ( $validIp ) {
$user = $this->newFromName( $ip, self::RIGOR_NONE );
} else {
throw new InvalidArgumentException( 'Invalid IP address' ); throw new InvalidArgumentException( 'Invalid IP address' );
} }
$user = $this->newFromName( $ip, self::RIGOR_NONE );
} else { } else {
$user = new User(); $user = new User();
} }