From: Daimona Eaytoy Date: Sat, 7 Sep 2019 13:33:24 +0000 (+0200) Subject: auth: Use phan templates for getRequestByClass X-Git-Tag: 1.34.0-rc.0~327^2 X-Git-Url: http://git.cyclocoop.org/?a=commitdiff_plain;h=5485a3dda0b188b2ff4d8d90476437215ecb9442;p=lhc%2Fweb%2Fwiklou.git auth: Use phan templates for getRequestByClass Phan is clever enough to understand when the return value depends on the name of the string passed in. This avoids lots of @phan-var annotations in all subclasses. Note that PHPCS rejects @template, ref T232256. Change-Id: I7b7c7fae9c80320cad41bedc2972a3a5e22e19b0 --- diff --git a/includes/auth/AuthenticationRequest.php b/includes/auth/AuthenticationRequest.php index e7527d156f..168ae851af 100644 --- a/includes/auth/AuthenticationRequest.php +++ b/includes/auth/AuthenticationRequest.php @@ -246,13 +246,18 @@ abstract class AuthenticationRequest { } /** + * @codingStandardsIgnoreStart + * @template T + * @codingStandardsIgnoreEnd * Select a request by class name. * @param AuthenticationRequest[] $reqs * @param string $class Class name + * @phan-param class-string $class * @param bool $allowSubclasses If true, also returns any request that's a subclass of the given * class. * @return AuthenticationRequest|null Returns null if there is not exactly * one matching request. + * @phan-return T|null */ public static function getRequestByClass( array $reqs, $class, $allowSubclasses = false ) { $requests = array_filter( $reqs, function ( $req ) use ( $class, $allowSubclasses ) { diff --git a/includes/auth/ResetPasswordSecondaryAuthenticationProvider.php b/includes/auth/ResetPasswordSecondaryAuthenticationProvider.php index c831fc8c44..25a17544f1 100644 --- a/includes/auth/ResetPasswordSecondaryAuthenticationProvider.php +++ b/includes/auth/ResetPasswordSecondaryAuthenticationProvider.php @@ -96,7 +96,9 @@ class ResetPasswordSecondaryAuthenticationProvider extends AbstractSecondaryAuth } } + /** @var PasswordAuthenticationRequest $needReq */ $needReq = $data->req ?? new PasswordAuthenticationRequest(); + '@phan-var PasswordAuthenticationRequest $needReq'; if ( !$needReq->action ) { $needReq->action = AuthManager::ACTION_CHANGE; }