From e85265ada5611c4c9f610dd1a8daef783c466703 Mon Sep 17 00:00:00 2001 From: Fomafix Date: Sun, 24 Mar 2024 18:26:16 +0000 Subject: [PATCH] Improve PHP class references * Declare class names from other namespaces in the `use` block. * Use Foo::class instead of 'Foo' to reference a class name. Change-Id: I5a1aba6b0cc8842d71b6b6df0a0b67e16e5b6453 --- includes/ServiceWiring.php | 20 ++++++++++++-------- includes/SkinOptions.php | 5 +++-- includes/Skins/FeaturesHelper.php | 7 ++++--- tests/phpunit/skins/FeaturesHelperTest.php | 7 ++++--- 4 files changed, 23 insertions(+), 16 deletions(-) diff --git a/includes/ServiceWiring.php b/includes/ServiceWiring.php index 5f84a828c..bf8643686 100644 --- a/includes/ServiceWiring.php +++ b/includes/ServiceWiring.php @@ -23,7 +23,11 @@ use MediaWiki\Config\ServiceOptions; use MediaWiki\MediaWikiServices; use MediaWiki\Minerva\LanguagesHelper; use MediaWiki\Minerva\Menu\Definitions; -use MediaWiki\Minerva\Menu\PageActions as PageActionsMenu; +use MediaWiki\Minerva\Menu\PageActions\DefaultOverflowBuilder; +use MediaWiki\Minerva\Menu\PageActions\EmptyOverflowBuilder; +use MediaWiki\Minerva\Menu\PageActions\PageActionsDirector; +use MediaWiki\Minerva\Menu\PageActions\ToolbarBuilder; +use MediaWiki\Minerva\Menu\PageActions\UserNamespaceOverflowBuilder; use MediaWiki\Minerva\Permissions\IMinervaPagePermissions; use MediaWiki\Minerva\Permissions\MinervaPagePermissions; use MediaWiki\Minerva\SkinOptions; @@ -38,7 +42,7 @@ return [ ); }, 'Minerva.Menu.PageActionsDirector' => - static function ( MediaWikiServices $services ): PageActionsMenu\PageActionsDirector { + static function ( MediaWikiServices $services ): PageActionsDirector { /** * @var SkinOptions $skinOptions * @var SkinMinerva $skin @@ -65,7 +69,7 @@ return [ $watchlistManager = $services->getWatchlistManager(); - $toolbarBuilder = new PageActionsMenu\ToolbarBuilder( + $toolbarBuilder = new ToolbarBuilder( $title, $user, $context, @@ -73,28 +77,28 @@ return [ $skinOptions, $userPageHelper, $languagesHelper, - new ServiceOptions( PageActionsMenu\ToolbarBuilder::CONSTRUCTOR_OPTIONS, + new ServiceOptions( ToolbarBuilder::CONSTRUCTOR_OPTIONS, $services->getMainConfig() ), $watchlistManager ); if ( $skinOptions->get( SkinOptions::TOOLBAR_SUBMENU ) ) { $overflowBuilder = $userPageHelper->isUserPage() ? - new PageActionsMenu\UserNamespaceOverflowBuilder( + new UserNamespaceOverflowBuilder( $title, $context, $permissions, $languagesHelper ) : - new PageActionsMenu\DefaultOverflowBuilder( + new DefaultOverflowBuilder( $title, $context, $permissions ); } else { - $overflowBuilder = new PageActionsMenu\EmptyOverflowBuilder(); + $overflowBuilder = new EmptyOverflowBuilder(); } - return new PageActionsMenu\PageActionsDirector( + return new PageActionsDirector( $toolbarBuilder, $overflowBuilder, $context diff --git a/includes/SkinOptions.php b/includes/SkinOptions.php index 07faa4588..54d844a94 100644 --- a/includes/SkinOptions.php +++ b/includes/SkinOptions.php @@ -25,6 +25,7 @@ use MediaWiki\Minerva\Hooks\HookRunner; use MediaWiki\Minerva\Skins\SkinMinerva; use MediaWiki\Minerva\Skins\SkinUserPageHelper; use MobileContext; +use OutOfBoundsException; use Skin; /** @@ -99,7 +100,7 @@ final class SkinOptions { public function setMultiple( array $options ) { foreach ( $options as $option => $value ) { if ( !array_key_exists( $option, $this->skinOptions ) ) { - throw new \OutOfBoundsException( "SkinOption $option is not defined" ); + throw new OutOfBoundsException( "SkinOption $option is not defined" ); } } $this->skinOptions = array_merge( $this->skinOptions, $options ); @@ -112,7 +113,7 @@ final class SkinOptions { */ public function get( $key ) { if ( !array_key_exists( $key, $this->skinOptions ) ) { - throw new \OutOfBoundsException( "SkinOption $key doesn't exist" ); + throw new OutOfBoundsException( "SkinOption $key doesn't exist" ); } return $this->skinOptions[$key]; } diff --git a/includes/Skins/FeaturesHelper.php b/includes/Skins/FeaturesHelper.php index a147097be..a591afd67 100644 --- a/includes/Skins/FeaturesHelper.php +++ b/includes/Skins/FeaturesHelper.php @@ -3,6 +3,7 @@ namespace MediaWiki\Minerva\Skins; use MediaWiki\Request\WebRequest; +use MediaWiki\Skins\Vector\ConfigHelper; use MediaWiki\Title\Title; class FeaturesHelper { @@ -27,8 +28,8 @@ class FeaturesHelper { * @internal only for use inside tests. */ public function shouldDisableNightMode( array $options, WebRequest $request, Title $title = null ) { - return class_exists( 'MediaWiki\Skins\Vector\ConfigHelper' ) ? - \MediaWiki\Skins\Vector\ConfigHelper::shouldDisable( - $options, $request, $title ) : false; + return class_exists( ConfigHelper::class ) ? + ConfigHelper::shouldDisable( $options, $request, $title ) : + false; } } diff --git a/tests/phpunit/skins/FeaturesHelperTest.php b/tests/phpunit/skins/FeaturesHelperTest.php index 2be687717..43f9591f4 100644 --- a/tests/phpunit/skins/FeaturesHelperTest.php +++ b/tests/phpunit/skins/FeaturesHelperTest.php @@ -6,6 +6,7 @@ use MediaWiki\Minerva\Skins\FeaturesHelper; use MediaWiki\Request\WebRequest; use MediaWiki\Title\Title; use MediaWikiIntegrationTestCase; +use RequestContext; /** * @group MinervaNeue @@ -25,9 +26,9 @@ class FeaturesHelperTest extends MediaWikiIntegrationTestCase { ] ] ]; - $context = new \RequestContext(); + $context = new RequestContext(); $request = $context->getRequest(); - $editContext = new \RequestContext(); + $editContext = new RequestContext(); $editRequest = $context->getRequest(); $editRequest->setVal( 'action', 'edit' ); $mainTitle = Title::makeTitle( NS_MAIN, 'Main Page' ); @@ -67,7 +68,7 @@ class FeaturesHelperTest extends MediaWikiIntegrationTestCase { ] ] ]; - $context = new \RequestContext(); + $context = new RequestContext(); $request = $context->getRequest(); $includedTitle = Title::makeTitle( NS_MAIN, 'Included Page' ); $featuresHelper = new FeaturesHelper();