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
This commit is contained in:
Fomafix 2024-03-24 18:26:16 +00:00
parent bb87e3d2de
commit e85265ada5
4 changed files with 23 additions and 16 deletions

View file

@ -23,7 +23,11 @@ use MediaWiki\Config\ServiceOptions;
use MediaWiki\MediaWikiServices; use MediaWiki\MediaWikiServices;
use MediaWiki\Minerva\LanguagesHelper; use MediaWiki\Minerva\LanguagesHelper;
use MediaWiki\Minerva\Menu\Definitions; 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\IMinervaPagePermissions;
use MediaWiki\Minerva\Permissions\MinervaPagePermissions; use MediaWiki\Minerva\Permissions\MinervaPagePermissions;
use MediaWiki\Minerva\SkinOptions; use MediaWiki\Minerva\SkinOptions;
@ -38,7 +42,7 @@ return [
); );
}, },
'Minerva.Menu.PageActionsDirector' => 'Minerva.Menu.PageActionsDirector' =>
static function ( MediaWikiServices $services ): PageActionsMenu\PageActionsDirector { static function ( MediaWikiServices $services ): PageActionsDirector {
/** /**
* @var SkinOptions $skinOptions * @var SkinOptions $skinOptions
* @var SkinMinerva $skin * @var SkinMinerva $skin
@ -65,7 +69,7 @@ return [
$watchlistManager = $services->getWatchlistManager(); $watchlistManager = $services->getWatchlistManager();
$toolbarBuilder = new PageActionsMenu\ToolbarBuilder( $toolbarBuilder = new ToolbarBuilder(
$title, $title,
$user, $user,
$context, $context,
@ -73,28 +77,28 @@ return [
$skinOptions, $skinOptions,
$userPageHelper, $userPageHelper,
$languagesHelper, $languagesHelper,
new ServiceOptions( PageActionsMenu\ToolbarBuilder::CONSTRUCTOR_OPTIONS, new ServiceOptions( ToolbarBuilder::CONSTRUCTOR_OPTIONS,
$services->getMainConfig() ), $services->getMainConfig() ),
$watchlistManager $watchlistManager
); );
if ( $skinOptions->get( SkinOptions::TOOLBAR_SUBMENU ) ) { if ( $skinOptions->get( SkinOptions::TOOLBAR_SUBMENU ) ) {
$overflowBuilder = $userPageHelper->isUserPage() ? $overflowBuilder = $userPageHelper->isUserPage() ?
new PageActionsMenu\UserNamespaceOverflowBuilder( new UserNamespaceOverflowBuilder(
$title, $title,
$context, $context,
$permissions, $permissions,
$languagesHelper $languagesHelper
) : ) :
new PageActionsMenu\DefaultOverflowBuilder( new DefaultOverflowBuilder(
$title, $title,
$context, $context,
$permissions $permissions
); );
} else { } else {
$overflowBuilder = new PageActionsMenu\EmptyOverflowBuilder(); $overflowBuilder = new EmptyOverflowBuilder();
} }
return new PageActionsMenu\PageActionsDirector( return new PageActionsDirector(
$toolbarBuilder, $toolbarBuilder,
$overflowBuilder, $overflowBuilder,
$context $context

View file

@ -25,6 +25,7 @@ use MediaWiki\Minerva\Hooks\HookRunner;
use MediaWiki\Minerva\Skins\SkinMinerva; use MediaWiki\Minerva\Skins\SkinMinerva;
use MediaWiki\Minerva\Skins\SkinUserPageHelper; use MediaWiki\Minerva\Skins\SkinUserPageHelper;
use MobileContext; use MobileContext;
use OutOfBoundsException;
use Skin; use Skin;
/** /**
@ -99,7 +100,7 @@ final class SkinOptions {
public function setMultiple( array $options ) { public function setMultiple( array $options ) {
foreach ( $options as $option => $value ) { foreach ( $options as $option => $value ) {
if ( !array_key_exists( $option, $this->skinOptions ) ) { 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 ); $this->skinOptions = array_merge( $this->skinOptions, $options );
@ -112,7 +113,7 @@ final class SkinOptions {
*/ */
public function get( $key ) { public function get( $key ) {
if ( !array_key_exists( $key, $this->skinOptions ) ) { 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]; return $this->skinOptions[$key];
} }

View file

@ -3,6 +3,7 @@
namespace MediaWiki\Minerva\Skins; namespace MediaWiki\Minerva\Skins;
use MediaWiki\Request\WebRequest; use MediaWiki\Request\WebRequest;
use MediaWiki\Skins\Vector\ConfigHelper;
use MediaWiki\Title\Title; use MediaWiki\Title\Title;
class FeaturesHelper { class FeaturesHelper {
@ -27,8 +28,8 @@ class FeaturesHelper {
* @internal only for use inside tests. * @internal only for use inside tests.
*/ */
public function shouldDisableNightMode( array $options, WebRequest $request, Title $title = null ) { public function shouldDisableNightMode( array $options, WebRequest $request, Title $title = null ) {
return class_exists( 'MediaWiki\Skins\Vector\ConfigHelper' ) ? return class_exists( ConfigHelper::class ) ?
\MediaWiki\Skins\Vector\ConfigHelper::shouldDisable( ConfigHelper::shouldDisable( $options, $request, $title ) :
$options, $request, $title ) : false; false;
} }
} }

View file

@ -6,6 +6,7 @@ use MediaWiki\Minerva\Skins\FeaturesHelper;
use MediaWiki\Request\WebRequest; use MediaWiki\Request\WebRequest;
use MediaWiki\Title\Title; use MediaWiki\Title\Title;
use MediaWikiIntegrationTestCase; use MediaWikiIntegrationTestCase;
use RequestContext;
/** /**
* @group MinervaNeue * @group MinervaNeue
@ -25,9 +26,9 @@ class FeaturesHelperTest extends MediaWikiIntegrationTestCase {
] ]
] ]
]; ];
$context = new \RequestContext(); $context = new RequestContext();
$request = $context->getRequest(); $request = $context->getRequest();
$editContext = new \RequestContext(); $editContext = new RequestContext();
$editRequest = $context->getRequest(); $editRequest = $context->getRequest();
$editRequest->setVal( 'action', 'edit' ); $editRequest->setVal( 'action', 'edit' );
$mainTitle = Title::makeTitle( NS_MAIN, 'Main Page' ); $mainTitle = Title::makeTitle( NS_MAIN, 'Main Page' );
@ -67,7 +68,7 @@ class FeaturesHelperTest extends MediaWikiIntegrationTestCase {
] ]
] ]
]; ];
$context = new \RequestContext(); $context = new RequestContext();
$request = $context->getRequest(); $request = $context->getRequest();
$includedTitle = Title::makeTitle( NS_MAIN, 'Included Page' ); $includedTitle = Title::makeTitle( NS_MAIN, 'Included Page' );
$featuresHelper = new FeaturesHelper(); $featuresHelper = new FeaturesHelper();