Fix remaining PHPCS exclusions

Add some return type hints on private methods in OATHManage

Change-Id: I8580348f5460b59c21bfca07b7c4cb92ea6be43f
This commit is contained in:
Reedy 2023-10-11 00:20:01 +01:00
parent c56496d62f
commit f2080c1bb9
3 changed files with 39 additions and 59 deletions

View file

@ -1,9 +1,6 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<ruleset name="MediaWiki"> <ruleset name="MediaWiki">
<rule ref="./vendor/mediawiki/mediawiki-codesniffer/MediaWiki"> <rule ref="./vendor/mediawiki/mediawiki-codesniffer/MediaWiki" />
<exclude name="MediaWiki.Commenting.FunctionComment.MissingDocumentationPrivate" />
<exclude name="MediaWiki.Commenting.PropertyDocumentation.MissingDocumentationPublic" />
</rule>
<file>.</file> <file>.</file>
<arg name="encoding" value="UTF-8" /> <arg name="encoding" value="UTF-8" />
<arg name="extensions" value="php,sample" /> <arg name="extensions" value="php,sample" />

View file

@ -27,6 +27,7 @@ use MediaWiki\Language\RawMessage;
* by the server and the client. * by the server and the client.
*/ */
class TOTPAuthenticationRequest extends AuthenticationRequest { class TOTPAuthenticationRequest extends AuthenticationRequest {
/** @var string */
public $OATHToken; public $OATHToken;
public function describeCredentials() { public function describeCredentials() {

View file

@ -42,20 +42,11 @@ class OATHManage extends SpecialPage {
public const ACTION_ENABLE = 'enable'; public const ACTION_ENABLE = 'enable';
public const ACTION_DISABLE = 'disable'; public const ACTION_DISABLE = 'disable';
/** protected OATHAuthModuleRegistry $moduleRegistry;
* @var OATHAuthModuleRegistry
*/
protected $moduleRegistry;
/** protected OATHUserRepository $userRepo;
* @var OATHUserRepository
*/
protected $userRepo;
/** protected OATHUser $authUser;
* @var OATHUser
*/
protected $authUser;
/** /**
* @var string * @var string
@ -76,7 +67,7 @@ class OATHManage extends SpecialPage {
* @throws ConfigException * @throws ConfigException
* @throws MWException * @throws MWException
*/ */
public function __construct( $userRepo, OATHAuthModuleRegistry $moduleRegistry ) { public function __construct( OATHUserRepository $userRepo, OATHAuthModuleRegistry $moduleRegistry ) {
parent::__construct( 'OATHManage', 'oathauth-enable' ); parent::__construct( 'OATHManage', 'oathauth-enable' );
$this->userRepo = $userRepo; $this->userRepo = $userRepo;
@ -148,39 +139,39 @@ class OATHManage extends SpecialPage {
} }
} }
private function setAction() { private function setAction(): void {
$this->action = $this->getRequest()->getVal( 'action', '' ); $this->action = $this->getRequest()->getVal( 'action', '' );
} }
private function setModule() { private function setModule(): void {
$moduleKey = $this->getRequest()->getVal( 'module', '' ); $moduleKey = $this->getRequest()->getVal( 'module', '' );
$this->requestedModule = $this->moduleRegistry->getModuleByKey( $moduleKey ); $this->requestedModule = $this->moduleRegistry->getModuleByKey( $moduleKey );
} }
private function hasEnabled() { private function hasEnabled(): bool {
return $this->authUser->getModule() instanceof IModule; return $this->authUser->getModule() instanceof IModule;
} }
private function getEnabled() { private function getEnabled(): ?IModule {
return $this->hasEnabled() ? $this->authUser->getModule() : null; return $this->hasEnabled() ? $this->authUser->getModule() : null;
} }
private function addEnabledHTML() { private function addEnabledHTML(): void {
$this->addHeading( $this->msg( 'oathauth-ui-enabled-module' ) ); $this->addHeading( $this->msg( 'oathauth-ui-enabled-module' ) );
$this->addModuleHTML( $this->getEnabled() ); $this->addModuleHTML( $this->getEnabled() );
} }
private function addAlternativesHTML() { private function addAlternativesHTML(): void {
$this->addHeading( $this->msg( 'oathauth-ui-not-enabled-modules' ) ); $this->addHeading( $this->msg( 'oathauth-ui-not-enabled-modules' ) );
$this->addInactiveHTML(); $this->addInactiveHTML();
} }
private function nothingEnabled() { private function nothingEnabled(): void {
$this->addHeading( $this->msg( 'oathauth-ui-available-modules' ) ); $this->addHeading( $this->msg( 'oathauth-ui-available-modules' ) );
$this->addInactiveHTML(); $this->addInactiveHTML();
} }
private function addInactiveHTML() { private function addInactiveHTML(): void {
foreach ( $this->moduleRegistry->getAllModules() as $module ) { foreach ( $this->moduleRegistry->getAllModules() as $module ) {
if ( $this->isModuleEnabled( $module ) ) { if ( $this->isModuleEnabled( $module ) ) {
continue; continue;
@ -189,20 +180,20 @@ class OATHManage extends SpecialPage {
} }
} }
private function addGeneralHelp() { private function addGeneralHelp(): void {
$this->getOutput()->addHTML( $this->msg( $this->getOutput()->addHTML( $this->msg(
'oathauth-ui-general-help' 'oathauth-ui-general-help'
)->parseAsBlock() ); )->parseAsBlock() );
} }
private function addModuleHTML( IModule $module ) { private function addModuleHTML( ?IModule $module ): void {
if ( $this->isModuleRequested( $module ) ) { if ( $module instanceof IModule && $this->isModuleRequested( $module ) ) {
$this->addCustomContent( $module ); $this->addCustomContent( $module );
return; return;
} }
$panel = $this->getGenericContent( $module ); $panel = $this->getGenericContent( $module );
if ( $this->isModuleEnabled( $module ) ) { if ( $module instanceof IModule && $this->isModuleEnabled( $module ) ) {
$this->addCustomContent( $module, $panel ); $this->addCustomContent( $module, $panel );
} }
@ -211,11 +202,8 @@ class OATHManage extends SpecialPage {
/** /**
* Get the panel with generic content for a module * Get the panel with generic content for a module
*
* @param IModule $module
* @return PanelLayout
*/ */
private function getGenericContent( IModule $module ) { private function getGenericContent( ?IModule $module ): PanelLayout {
$modulePanel = new PanelLayout( [ $modulePanel = new PanelLayout( [
'framed' => true, 'framed' => true,
'expanded' => false, 'expanded' => false,
@ -249,11 +237,7 @@ class OATHManage extends SpecialPage {
return $modulePanel; return $modulePanel;
} }
/** private function addCustomContent( IModule $module, PanelLayout $panel = null ): void {
* @param IModule $module
* @param PanelLayout|null $panel
*/
private function addCustomContent( IModule $module, $panel = null ) {
$form = $module->getManageForm( $form = $module->getManageForm(
$this->action, $this->action,
$this->authUser, $this->authUser,
@ -271,24 +255,27 @@ class OATHManage extends SpecialPage {
} }
} }
private function addHeading( Message $message ) { private function addHeading( Message $message ): void {
$this->getOutput()->addHTML( Html::element( 'h2', [], $message->text() ) ); $this->getOutput()->addHTML( Html::element( 'h2', [], $message->text() ) );
} }
private function shouldShowGenericButtons() { private function shouldShowGenericButtons(): bool {
return !$this->requestedModule instanceof IModule || !$this->isGenericAction(); return !$this->requestedModule instanceof IModule || !$this->isGenericAction();
} }
private function isModuleRequested( IModule $module ) { private function isModuleRequested( ?IModule $module ): bool {
return ( return (
$this->requestedModule instanceof IModule $this->requestedModule instanceof IModule
&& $module instanceof IModule
&& $this->requestedModule->getName() === $module->getName() && $this->requestedModule->getName() === $module->getName()
); );
} }
private function isModuleEnabled( IModule $module ) { private function isModuleEnabled( ?IModule $module ): bool {
if ( $this->getEnabled() instanceof IModule ) { $enabled = $this->getEnabled();
return $this->getEnabled()->getName() === $module->getName(); if ( $enabled instanceof IModule ) {
return $module instanceof IModule
&& $enabled->getName() === $module->getName();
} }
return false; return false;
} }
@ -299,7 +286,7 @@ class OATHManage extends SpecialPage {
* @param mixed $form * @param mixed $form
* @return bool * @return bool
*/ */
private function isValidFormType( $form ) { private function isValidFormType( $form ): bool {
if ( !( $form instanceof HTMLForm ) ) { if ( !( $form instanceof HTMLForm ) ) {
return false; return false;
} }
@ -311,11 +298,7 @@ class OATHManage extends SpecialPage {
return true; return true;
} }
/** private function ensureRequiredFormFields( IManageForm $form, IModule $module ): void {
* @param IManageForm $form
* @param IModule $module
*/
private function ensureRequiredFormFields( IManageForm $form, IModule $module ) {
if ( !$form->hasField( 'module' ) ) { if ( !$form->hasField( 'module' ) ) {
$form->addHiddenField( 'module', $module->getName() ); $form->addHiddenField( 'module', $module->getName() );
} }
@ -326,9 +309,9 @@ class OATHManage extends SpecialPage {
/** /**
* When performing an action on a module (like enable/disable), * When performing an action on a module (like enable/disable),
* page should contain only the form for that action * page should contain only the form for that action.
*/ */
private function clearPage() { private function clearPage(): void {
if ( $this->isGenericAction() ) { if ( $this->isGenericAction() ) {
$displayName = $this->requestedModule->getDisplayName(); $displayName = $this->requestedModule->getDisplayName();
$pageTitle = $this->isModuleEnabled( $this->requestedModule ) ? $pageTitle = $this->isModuleEnabled( $this->requestedModule ) ?
@ -343,14 +326,13 @@ class OATHManage extends SpecialPage {
/** /**
* The enable and disable actions are generic, and all modules must * The enable and disable actions are generic, and all modules must
* implement them, while all other actions are module-specific * implement them, while all other actions are module-specific.
* @return bool
*/ */
private function isGenericAction() { private function isGenericAction(): bool {
return in_array( $this->action, [ static::ACTION_ENABLE, static::ACTION_DISABLE ] ); return in_array( $this->action, [ static::ACTION_ENABLE, static::ACTION_DISABLE ] );
} }
private function hasAlternativeModules() { private function hasAlternativeModules(): bool {
foreach ( $this->moduleRegistry->getAllModules() as $module ) { foreach ( $this->moduleRegistry->getAllModules() as $module ) {
if ( !$this->isModuleEnabled( $module ) ) { if ( !$this->isModuleEnabled( $module ) ) {
return true; return true;
@ -359,13 +341,13 @@ class OATHManage extends SpecialPage {
return false; return false;
} }
private function shouldShowDisableWarning() { private function shouldShowDisableWarning(): bool {
return $this->getRequest()->getBool( 'warn' ) && return $this->getRequest()->getBool( 'warn' ) &&
$this->requestedModule instanceof IModule && $this->requestedModule instanceof IModule &&
$this->getEnabled() instanceof IModule; $this->getEnabled() instanceof IModule;
} }
private function showDisableWarning() { private function showDisableWarning(): void {
$panel = new PanelLayout( [ $panel = new PanelLayout( [
'padded' => true, 'padded' => true,
'framed' => true, 'framed' => true,
@ -407,7 +389,7 @@ class OATHManage extends SpecialPage {
$this->getOutput()->addHTML( $panel->toString() ); $this->getOutput()->addHTML( $panel->toString() );
} }
private function isSwitch() { private function isSwitch(): bool {
return $this->requestedModule instanceof IModule && return $this->requestedModule instanceof IModule &&
$this->action === static::ACTION_ENABLE && $this->action === static::ACTION_ENABLE &&
$this->getEnabled() instanceof IModule; $this->getEnabled() instanceof IModule;