From: Tim Düsterhus Date: Wed, 10 Aug 2022 13:38:14 +0000 (+0200) Subject: Add proper types to the `*AuthAction` controllers X-Git-Tag: 6.0.0_Alpha_1~1043^2~1 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=f41cd47c6674ab0bfeeae96b13fb91574100880a;p=GitHub%2FWoltLab%2FWCF.git Add proper types to the `*AuthAction` controllers --- diff --git a/wcfsetup/install/files/lib/action/FacebookAuthAction.class.php b/wcfsetup/install/files/lib/action/FacebookAuthAction.class.php index 8c2718e4b8..ac512c1b57 100644 --- a/wcfsetup/install/files/lib/action/FacebookAuthAction.class.php +++ b/wcfsetup/install/files/lib/action/FacebookAuthAction.class.php @@ -4,6 +4,7 @@ namespace wcf\action; use GuzzleHttp\Psr7\Request; use Laminas\Diactoros\Response\RedirectResponse; +use Psr\Http\Message\ResponseInterface; use wcf\data\user\User; use wcf\form\AccountManagementForm; use wcf\form\RegisterForm; @@ -120,7 +121,7 @@ final class FacebookAuthAction extends AbstractOauth2Action /** * @inheritDoc */ - protected function processUser(OauthUser $oauthUser) + protected function processUser(OauthUser $oauthUser): ResponseInterface { $user = User::getUserByAuthData('facebook:' . $oauthUser->getId()); diff --git a/wcfsetup/install/files/lib/action/GithubAuthAction.class.php b/wcfsetup/install/files/lib/action/GithubAuthAction.class.php index 62b6ce0570..90b00ef4e8 100644 --- a/wcfsetup/install/files/lib/action/GithubAuthAction.class.php +++ b/wcfsetup/install/files/lib/action/GithubAuthAction.class.php @@ -5,6 +5,7 @@ namespace wcf\action; use GuzzleHttp\Psr7\Request; use Laminas\Diactoros\Response\RedirectResponse; use Psr\Http\Client\ClientExceptionInterface; +use Psr\Http\Message\ResponseInterface; use wcf\data\user\User; use wcf\form\AccountManagementForm; use wcf\form\RegisterForm; @@ -110,7 +111,7 @@ final class GithubAuthAction extends AbstractOauth2Action /** * @inheritDoc */ - protected function processUser(OauthUser $oauthUser) + protected function processUser(OauthUser $oauthUser): ResponseInterface { $user = User::getUserByAuthData('github:' . $oauthUser->getId()); diff --git a/wcfsetup/install/files/lib/action/GoogleAuthAction.class.php b/wcfsetup/install/files/lib/action/GoogleAuthAction.class.php index 69638cf66c..402427e2a7 100644 --- a/wcfsetup/install/files/lib/action/GoogleAuthAction.class.php +++ b/wcfsetup/install/files/lib/action/GoogleAuthAction.class.php @@ -4,6 +4,7 @@ namespace wcf\action; use GuzzleHttp\Psr7\Request; use Laminas\Diactoros\Response\RedirectResponse; +use Psr\Http\Message\ResponseInterface; use wcf\data\user\User; use wcf\form\AccountManagementForm; use wcf\form\RegisterForm; @@ -41,7 +42,7 @@ final class GoogleAuthAction extends AbstractOauth2Action */ private function getConfiguration() { - if (!$this->configuration) { + if (!isset($this->configuration)) { $request = new Request('GET', 'https://accounts.google.com/.well-known/openid-configuration'); $response = $this->getHttpClient()->send($request); @@ -132,7 +133,7 @@ final class GoogleAuthAction extends AbstractOauth2Action /** * @inheritDoc */ - protected function processUser(OauthUser $oauthUser) + protected function processUser(OauthUser $oauthUser): ResponseInterface { $user = User::getUserByAuthData('google:' . $oauthUser->getId()); diff --git a/wcfsetup/install/files/lib/action/TwitterAuthAction.class.php b/wcfsetup/install/files/lib/action/TwitterAuthAction.class.php index 0e859e03cd..009f4fd711 100644 --- a/wcfsetup/install/files/lib/action/TwitterAuthAction.class.php +++ b/wcfsetup/install/files/lib/action/TwitterAuthAction.class.php @@ -8,6 +8,7 @@ use Laminas\Diactoros\Response\RedirectResponse; use ParagonIE\ConstantTime\Base64; use ParagonIE\ConstantTime\Hex; use Psr\Http\Client\ClientExceptionInterface; +use Psr\Http\Message\ResponseInterface; use wcf\data\user\User; use wcf\form\RegisterForm; use wcf\system\event\EventHandler; @@ -37,10 +38,7 @@ final class TwitterAuthAction extends AbstractAction */ public $neededModules = ['TWITTER_PUBLIC_KEY', 'TWITTER_PRIVATE_KEY']; - /** - * @var ClientInterface - */ - private $httpClient; + private ClientInterface $httpClient; /** * @inheritDoc @@ -57,7 +55,7 @@ final class TwitterAuthAction extends AbstractAction /** * @inheritDoc */ - public function execute() + public function execute(): ResponseInterface { parent::execute(); @@ -106,7 +104,7 @@ final class TwitterAuthAction extends AbstractAction /** * Processes the user (e.g. by registering session variables and redirecting somewhere). */ - protected function processUser(OauthUser $oauthUser) + protected function processUser(OauthUser $oauthUser): ResponseInterface { $user = User::getUserByAuthData('twitter:' . $oauthUser->getId()); @@ -323,7 +321,7 @@ final class TwitterAuthAction extends AbstractAction /** * Initiates the OAuth flow by redirecting to the '/authenticate' URL. */ - private function initiate() + private function initiate(): ResponseInterface { $data = $this->getRequestToken(); @@ -343,9 +341,8 @@ final class TwitterAuthAction extends AbstractAction * Builds the OAuth authorization header. * * @param array $parameters - * @return string */ - public function buildOAuthHeader(array $parameters) + public function buildOAuthHeader(array $parameters): string { $header = ''; foreach ($parameters as $key => $val) { @@ -364,20 +361,14 @@ final class TwitterAuthAction extends AbstractAction /** * Creates an OAuth 1 signature. - * - * @param string $url - * @param array $parameters - * @param string $tokenSecret - * @param string $method - * @return string */ public function createSignature( - $url, + string $url, array $parameters, #[\SensitiveParameter] - $tokenSecret = '', - $method = 'POST' - ) { + string $tokenSecret = '', + string $method = 'POST' + ): string { $tmp = []; foreach ($parameters as $key => $val) { $tmp[\rawurlencode($key)] = \rawurlencode($val); @@ -405,7 +396,7 @@ final class TwitterAuthAction extends AbstractAction */ final protected function getHttpClient(): ClientInterface { - if (!$this->httpClient) { + if (!isset($this->httpClient)) { $this->httpClient = HttpFactory::makeClientWithTimeout(5); }