From 7297235b2a1a705c64cffe11453aa688de4f1a13 Mon Sep 17 00:00:00 2001 From: Daimona Eaytoy Date: Tue, 3 Dec 2019 17:08:13 +0000 Subject: [PATCH] Pass correct type to constructor Although there was no docblock on CaptchaAuthenticationRequest::__construct, the method is supposed to get a string and an array, as that's how the class members are documented and used. Trying to access offsets of null resulted in PHP notices on PHP 7.4, as seen in the experimental job for various repos. Bug: T239726 Change-Id: Idd073ebf3d560543ec225479de060e3c198847eb --- .../includes/ReCaptchaNoCaptchaAuthenticationRequest.php | 2 +- SimpleCaptcha/SimpleCaptcha.php | 2 +- includes/auth/CaptchaAuthenticationRequest.php | 6 +++++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/ReCaptchaNoCaptcha/includes/ReCaptchaNoCaptchaAuthenticationRequest.php b/ReCaptchaNoCaptcha/includes/ReCaptchaNoCaptchaAuthenticationRequest.php index 01b845dd0..c020f2d8f 100644 --- a/ReCaptchaNoCaptcha/includes/ReCaptchaNoCaptchaAuthenticationRequest.php +++ b/ReCaptchaNoCaptcha/includes/ReCaptchaNoCaptchaAuthenticationRequest.php @@ -8,7 +8,7 @@ use MediaWiki\Auth\AuthenticationRequest; */ class ReCaptchaNoCaptchaAuthenticationRequest extends CaptchaAuthenticationRequest { public function __construct() { - parent::__construct( null, null ); + parent::__construct( '', [] ); } public function loadFromSubmission( array $data ) { diff --git a/SimpleCaptcha/SimpleCaptcha.php b/SimpleCaptcha/SimpleCaptcha.php index 0d9606214..238a23f82 100644 --- a/SimpleCaptcha/SimpleCaptcha.php +++ b/SimpleCaptcha/SimpleCaptcha.php @@ -192,7 +192,7 @@ class SimpleCaptcha { * @return string Description of the captcha. Format is not specified; could be text, HTML, URL... */ public function getCaptchaInfo( $captchaData, $id ) { - return $captchaData['question'] . ' ='; + return array_key_exists( 'question', $captchaData ) ? ( $captchaData['question'] . ' =' ) : ''; } /** diff --git a/includes/auth/CaptchaAuthenticationRequest.php b/includes/auth/CaptchaAuthenticationRequest.php index d19a9dbd9..d3e785442 100644 --- a/includes/auth/CaptchaAuthenticationRequest.php +++ b/includes/auth/CaptchaAuthenticationRequest.php @@ -18,6 +18,10 @@ class CaptchaAuthenticationRequest extends AuthenticationRequest { /** @var string Captcha solution submitted by the user. */ public $captchaWord; + /** + * @param string $id + * @param array $data + */ public function __construct( $id, $data ) { $this->captchaId = $id; $this->captchaData = $data; @@ -83,7 +87,7 @@ class CaptchaAuthenticationRequest extends AuthenticationRequest { } public static function __set_state( $data ) { - $ret = new static( null, null ); + $ret = new static( '', [] ); foreach ( $data as $k => $v ) { $ret->$k = $v; }