From 964b4fb6290caf9c9e15a2bdb404885864568d07 Mon Sep 17 00:00:00 2001 From: thiemowmde Date: Tue, 19 Sep 2023 10:31:41 +0200 Subject: [PATCH] Add a few strict types to help the MediaWiki CodeSniffer This is mostly motivated by the (currently disabled) MediaWiki CodeSniffer sniff that requires types to be documented, either with a PHPDoc comment or a strict type. In these cases here I feel like a strict type is the better, more sustainable fix. I touched only places in the code where it's really, really obvious that this is the correct type. Change-Id: I89f202af1d05387c8944c83104ba1d7c642e6475 --- client/includes/ClientHooks.php | 2 +- .../RecentChanges/ChangeLineFormatterTest.php | 14 +++++++------- .../ItemPropertyIdHtmlLinkFormatterTest.php | 2 +- lib/tests/phpunit/SimpleCacheWithBagOStuffTest.php | 6 +----- .../Sql/Terms/DatabaseItemTermStoreWriterTest.php | 3 ++- repo/includes/Content/EntityContent.php | 2 +- .../ParserOutput/EntityTermsViewFactory.php | 2 +- .../Store/Sql/PropertyInfoTableBuilder.php | 2 +- 8 files changed, 15 insertions(+), 18 deletions(-) diff --git a/client/includes/ClientHooks.php b/client/includes/ClientHooks.php index 65af26c2bc8..6fa58714d28 100644 --- a/client/includes/ClientHooks.php +++ b/client/includes/ClientHooks.php @@ -232,7 +232,7 @@ private static function parseEntityId( ?string $prefixedId ): ?EntityId { * Used to propagate configuration for the linkitem feature to JavaScript. * This is used in the "wikibase.client.linkitem.init" module. */ - public static function getLinkitemConfiguration() { + public static function getLinkitemConfiguration(): array { $cache = MediaWikiServices::getInstance()->getLocalServerObjectCache(); $key = $cache->makeKey( 'wikibase-client', diff --git a/client/tests/phpunit/integration/includes/RecentChanges/ChangeLineFormatterTest.php b/client/tests/phpunit/integration/includes/RecentChanges/ChangeLineFormatterTest.php index d1e00755845..7aeef7e822f 100644 --- a/client/tests/phpunit/integration/includes/RecentChanges/ChangeLineFormatterTest.php +++ b/client/tests/phpunit/integration/includes/RecentChanges/ChangeLineFormatterTest.php @@ -5,9 +5,12 @@ use ChangesList; use DerivativeContext; use HamcrestPHPUnitIntegration; +use MediaWiki\CommentFormatter\CommentFormatter; +use MediaWiki\Linker\LinkRenderer; use MediaWiki\MediaWikiServices; use MediaWiki\Revision\RevisionRecord; use MediaWiki\Title\Title; +use MediaWiki\User\UserNameUtils; use MediaWikiLangTestCase; use RecentChange; use RequestContext; @@ -35,13 +38,10 @@ class ChangeLineFormatterTest extends MediaWikiLangTestCase { use HamcrestPHPUnitIntegration; - protected $repoLinker; - - protected $userNameUtils; - - protected $linkRenderer; - - protected $commentFormatter; + protected RepoLinker $repoLinker; + protected UserNameUtils $userNameUtils; + protected LinkRenderer $linkRenderer; + protected CommentFormatter $commentFormatter; protected function setUp(): void { parent::setUp(); diff --git a/lib/tests/phpunit/Formatters/ItemPropertyIdHtmlLinkFormatterTest.php b/lib/tests/phpunit/Formatters/ItemPropertyIdHtmlLinkFormatterTest.php index b0beea99ed7..fc723917b4c 100644 --- a/lib/tests/phpunit/Formatters/ItemPropertyIdHtmlLinkFormatterTest.php +++ b/lib/tests/phpunit/Formatters/ItemPropertyIdHtmlLinkFormatterTest.php @@ -40,7 +40,7 @@ class ItemPropertyIdHtmlLinkFormatterTest extends MediaWikiIntegrationTestCase { /** @var LanguageNameLookup|MockObject */ private $languageNameLookup; - + /** @var string */ protected $currentUserLanguage; /** @var string[] List of fallback languages */ protected $fallbackChain = []; diff --git a/lib/tests/phpunit/SimpleCacheWithBagOStuffTest.php b/lib/tests/phpunit/SimpleCacheWithBagOStuffTest.php index 0a8825826ca..fb05ce567c7 100644 --- a/lib/tests/phpunit/SimpleCacheWithBagOStuffTest.php +++ b/lib/tests/phpunit/SimpleCacheWithBagOStuffTest.php @@ -147,11 +147,7 @@ public function testSecretCanNotBeEmpty() { new SimpleCacheWithBagOStuff( $inner, 'prefix', '' ); } - /** - * @param $inner - * @param $key - */ - protected function spoilTheSignature( $inner, $key ) { + protected function spoilTheSignature( HashBagOStuff $inner, string $key ): void { $value = $inner->get( $key ); list( $signature, $data ) = json_decode( $value ); $inner->set( $key, json_encode( [ 'wrong signature', $data ] ) ); diff --git a/lib/tests/phpunit/Store/Sql/Terms/DatabaseItemTermStoreWriterTest.php b/lib/tests/phpunit/Store/Sql/Terms/DatabaseItemTermStoreWriterTest.php index f5f2f12717c..46b8d803f43 100644 --- a/lib/tests/phpunit/Store/Sql/Terms/DatabaseItemTermStoreWriterTest.php +++ b/lib/tests/phpunit/Store/Sql/Terms/DatabaseItemTermStoreWriterTest.php @@ -2,6 +2,7 @@ namespace Wikibase\Lib\Tests\Store\Sql\Terms; +use JobQueueGroup; use MediaWikiIntegrationTestCase; use WANObjectCache; use Wikibase\DataModel\Entity\ItemId; @@ -45,7 +46,7 @@ class DatabaseItemTermStoreWriterTest extends MediaWikiIntegrationTestCase { /** @var Fingerprint */ private $fingerprintEmpty; - private $jobQueueMock; + private JobQueueGroup $jobQueueMock; /** * @var MockJobQueueFactory */ private $mockJobQueueFactory; diff --git a/repo/includes/Content/EntityContent.php b/repo/includes/Content/EntityContent.php index fa07928e7a5..874c8e5d51b 100644 --- a/repo/includes/Content/EntityContent.php +++ b/repo/includes/Content/EntityContent.php @@ -240,7 +240,7 @@ public function getTextForSummary( $maxLength = 250 ) { * @note This may or may not be consistent with what EntityContentCodec does. * It it intended to be used primarily for diffing. */ - private function getRedirectData() { + private function getRedirectData(): array { // NOTE: keep in sync with getPatchedRedirect $data = []; diff --git a/repo/includes/ParserOutput/EntityTermsViewFactory.php b/repo/includes/ParserOutput/EntityTermsViewFactory.php index 608dd412c88..c9d1169177a 100644 --- a/repo/includes/ParserOutput/EntityTermsViewFactory.php +++ b/repo/includes/ParserOutput/EntityTermsViewFactory.php @@ -94,7 +94,7 @@ private function newPlaceHolderEmittingEntityTermsView( * This is because the objects created from this factory are assumed to * write into ParserOutput which should not include any user-specific markup. */ - private function newTermboxView( Language $language ) { + private function newTermboxView( Language $language ): TermboxView { $textProvider = new MediaWikiLocalizedTextProvider( $language ); $services = MediaWikiServices::getInstance(); $repoSettings = WikibaseRepo::getSettings( $services ); diff --git a/repo/includes/Store/Sql/PropertyInfoTableBuilder.php b/repo/includes/Store/Sql/PropertyInfoTableBuilder.php index ad809195c68..5d6846d1acb 100644 --- a/repo/includes/Store/Sql/PropertyInfoTableBuilder.php +++ b/repo/includes/Store/Sql/PropertyInfoTableBuilder.php @@ -100,7 +100,7 @@ public function setReporter( MessageReporter $reporter ) { * Database updates a batched into multiple transactions. Do not call this * method within an (explicit) database transaction. */ - public function rebuildPropertyInfo() { + public function rebuildPropertyInfo(): int { $propertyNamespace = $this->entityNamespaceLookup->getEntityNamespace( Property::ENTITY_TYPE );