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
This commit is contained in:
Daimona Eaytoy 2019-12-03 17:08:13 +00:00
parent a9c698f83c
commit 7297235b2a
3 changed files with 7 additions and 3 deletions

View file

@ -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 ) {

View file

@ -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'] . ' =' ) : '';
}
/**

View file

@ -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;
}