diff --git a/SimpleCaptcha/SimpleCaptcha.php b/SimpleCaptcha/SimpleCaptcha.php index 27ac69155..e49eb4203 100644 --- a/SimpleCaptcha/SimpleCaptcha.php +++ b/SimpleCaptcha/SimpleCaptcha.php @@ -750,7 +750,7 @@ class SimpleCaptcha { } foreach ( $build as $key => $value ) { $regexes[] = $regexStart[$key] . - str_replace( '/', '\/', preg_replace( '|\\\*/|', '/', $build[$key] ) ) . + str_replace( '/', '\/', preg_replace( '|\\\*/|', '/', $value ) ) . $regexEnd[$key]; } return $regexes; @@ -1112,7 +1112,7 @@ class SimpleCaptcha { * Extract a list of all recognized HTTP links in the text. * @param Title $title * @param string $text - * @return array of strings + * @return string[] */ private function findLinks( $title, $text ) { $parser = MediaWikiServices::getInstance()->getParser(); diff --git a/includes/ConfirmEditHooks.php b/includes/ConfirmEditHooks.php index 97c8728b3..ecd81cfaa 100644 --- a/includes/ConfirmEditHooks.php +++ b/includes/ConfirmEditHooks.php @@ -14,12 +14,9 @@ class ConfirmEditHooks { public static function getInstance() { global $wgCaptcha, $wgCaptchaClass; - $class = $wgCaptchaClass; - if ( $class == null ) { - $class = 'SimpleCaptcha'; - } if ( !static::$instanceCreated ) { static::$instanceCreated = true; + $class = $wgCaptchaClass ?: SimpleCaptcha::class; $wgCaptcha = new $class; } diff --git a/includes/auth/CaptchaAuthenticationRequest.php b/includes/auth/CaptchaAuthenticationRequest.php index 2eaf28669..30e7b04dd 100644 --- a/includes/auth/CaptchaAuthenticationRequest.php +++ b/includes/auth/CaptchaAuthenticationRequest.php @@ -83,8 +83,7 @@ class CaptchaAuthenticationRequest extends AuthenticationRequest { } public function getMetadata() { - $captcha = ConfirmEditHooks::getInstance(); - return $captcha->describeCaptchaType(); + return ( ConfirmEditHooks::getInstance() )->describeCaptchaType(); } public static function __set_state( $data ) { diff --git a/includes/specials/SpecialCaptcha.php b/includes/specials/SpecialCaptcha.php index 2a66f7bb2..af68b073f 100644 --- a/includes/specials/SpecialCaptcha.php +++ b/includes/specials/SpecialCaptcha.php @@ -10,16 +10,13 @@ class SpecialCaptcha extends UnlistedSpecialPage { $instance = ConfirmEditHooks::getInstance(); - switch ( $par ) { - case "image": - if ( method_exists( $instance, 'showImage' ) ) { - // @todo: Do this in a more OOP way - /** @phan-suppress-next-line PhanUndeclaredMethod */ - return $instance->showImage(); - } - case "help": - default: - return $instance->showHelp(); + if ( $par === 'image' && method_exists( $instance, 'showImage' ) ) { + // @todo: Do this in a more OOP way + /** @phan-suppress-next-line PhanUndeclaredMethod */ + $instance->showImage(); + return; } + + $instance->showHelp(); } } diff --git a/includes/store/CaptchaCacheStore.php b/includes/store/CaptchaCacheStore.php index 6bf0439c9..87b49a8bb 100644 --- a/includes/store/CaptchaCacheStore.php +++ b/includes/store/CaptchaCacheStore.php @@ -25,12 +25,7 @@ class CaptchaCacheStore extends CaptchaStore { public function retrieve( $index ) { $cache = $this->cache; - $info = $cache->get( $cache->makeKey( 'captcha', $index ) ); - if ( $info ) { - return $info; - } else { - return false; - } + return $cache->get( $cache->makeKey( 'captcha', $index ) ) ?: false; } public function clear( $index ) {