Skip to content

Commit

Permalink
Merge "lib: Use type declaration on undocumented private functions"
Browse files Browse the repository at this point in the history
  • Loading branch information
jenkins-bot authored and Gerrit Code Review committed Feb 27, 2025
2 parents c9d74d5 + ea14c33 commit 29bebef
Show file tree
Hide file tree
Showing 39 changed files with 71 additions and 69 deletions.
2 changes: 1 addition & 1 deletion lib/includes/Formatters/CommonsInlineImageFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public function format( $value ) {
return $this->wrapThumb( $title, $thumb->toHtml() ) . $this->getCaptionHtml( $title, $file );
}

private function getThumbWidth( $thumbSize ) {
private function getThumbWidth( int $thumbSize ): int {
return $this->thumbLimits[$thumbSize] ?? self::FALLBACK_THUMBNAIL_WIDTH;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function getLabelDescriptionLookup( FormatterOptions $options ) {
}
}

private function newLanguageFallbackLabelDescriptionLookup( FormatterOptions $options ) {
private function newLanguageFallbackLabelDescriptionLookup( FormatterOptions $options ): CachingFallbackLabelDescriptionLookup {
$fallbackChain = $options->getOption( self::OPT_LANGUAGE_FALLBACK_CHAIN );

if ( !( $fallbackChain instanceof TermLanguageFallbackChain ) ) {
Expand All @@ -90,7 +90,7 @@ private function newLanguageFallbackLabelDescriptionLookup( FormatterOptions $op
);
}

private function newLanguageLabelDescriptionLookup( FormatterOptions $options ) {
private function newLanguageLabelDescriptionLookup( FormatterOptions $options ): LanguageLabelDescriptionLookup {
$languageCode = $options->getOption( ValueFormatter::OPT_LANG );

if ( !is_string( $languageCode ) ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function format( $value ) {
return wfEscapeWikiText( $this->coordinateFormatter->format( $value ) );
}

private function formatEarthCoordinate( GlobeCoordinateValue $value ) {
private function formatEarthCoordinate( GlobeCoordinateValue $value ): string {
return Html::rawElement( 'maplink', [
'latitude' => $value->getLatitude(),
'longitude' => $value->getLongitude(),
Expand Down
6 changes: 3 additions & 3 deletions lib/includes/Formatters/WikibaseValueFormatterBuilders.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public function __construct(
$this->languageFactory = $languageFactory;
}

private function newPlainEntityIdFormatter( FormatterOptions $options ) {
private function newPlainEntityIdFormatter( FormatterOptions $options ): EntityIdValueFormatter {
$labelDescriptionLookup = $this->labelDescriptionLookupFactory->getLabelDescriptionLookup( $options );
return new EntityIdValueFormatter(
new EntityIdLabelFormatter( $labelDescriptionLookup )
Expand Down Expand Up @@ -270,14 +270,14 @@ public function newItemIdHtmlLinkFormatter( FormatterOptions $options ) {
);
}

private function getNonCachingLookup( FormatterOptions $options ) {
private function getNonCachingLookup( FormatterOptions $options ): LanguageFallbackLabelDescriptionLookup {
return new LanguageFallbackLabelDescriptionLookup(
new EntityRetrievingTermLookup( $this->entityLookup ),
$options->getOption( FormatterLabelDescriptionLookupFactory::OPT_LANGUAGE_FALLBACK_CHAIN )
);
}

private function getLabelDescriptionLookup( FormatterOptions $options ) {
private function getLabelDescriptionLookup( FormatterOptions $options ): CachingFallbackLabelDescriptionLookup {
return new CachingFallbackLabelDescriptionLookup(
$this->cache,
$this->redirectResolvingLatestRevisionLookup,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function __construct( SnakUrlExpander $urlExpander ) {
$this->urlExpander = $urlExpander;
}

private function escapeWikitextInUrl( $url ) {
private function escapeWikitextInUrl( string $url ): string {
return str_replace( [
'[', ']', '<', '>', '\'', ' ', "\r", "\n", "\t",
], [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ private function convertToSearchResult( TermIndexEntry $termIndexEntry ) {
);
}

private function getTermIndexOptions() {
private function getTermIndexOptions(): array {
return [
'caseSensitive' => $this->termSearchOptions->getIsCaseSensitive(),
'prefixSearch' => $this->termSearchOptions->getIsPrefixSearch(),
Expand Down
5 changes: 3 additions & 2 deletions lib/includes/LanguageFallbackChainFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use MediaWiki\MediaWikiServices;
use MediaWiki\Registration\ExtensionRegistry;
use MediaWiki\User\User;
use MediaWiki\User\UserIdentity;

/**
* Object creating TermLanguageFallbackChain objects in Wikibase.
Expand Down Expand Up @@ -256,7 +257,7 @@ public function newFromUserAndLanguageCode( User $user, $languageCode ) {
return $languageFallbackChain;
}

private function getBabel( $languageCode, $user ) {
private function getBabel( string $languageCode, UserIdentity $user ): array {
$babel = [];

$babelCategoryNames = $this->getBabelCategoryNames();
Expand All @@ -282,7 +283,7 @@ private function getBabel( $languageCode, $user ) {
return $babel;
}

private function getBabelCategoryNames() {
private function getBabelCategoryNames(): array {
global $wgBabelCategoryNames;

$babelCategoryNames = array_filter(
Expand Down
2 changes: 1 addition & 1 deletion lib/includes/Normalization/SnakNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function normalize( Snak $snak ): Snak {
);
}

private function getNormalizer( PropertyId $propertyId, string $valueType ) {
private function getNormalizer( PropertyId $propertyId, string $valueType ): DataValueNormalizer {
$propertyIdSerialization = $propertyId->getSerialization();
if ( !array_key_exists( $propertyIdSerialization, $this->normalizers ) ) {
$this->normalizers[$propertyIdSerialization] = $this->makeNormalizer( $propertyId, $valueType );
Expand Down
2 changes: 1 addition & 1 deletion lib/includes/SimpleCacheWithBagOStuff.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public function has( $key ) {
return $result !== false;
}

private function assertKeysAreValid( $keys ): void {
private function assertKeysAreValid( array $keys ): void {
foreach ( $keys as $key ) {
$this->assertKeyIsValid( $key );
}
Expand Down
4 changes: 2 additions & 2 deletions lib/includes/Store/CacheAwarePropertyInfoStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,14 @@ public function removePropertyInfo( NumericPropertyId $propertyId ) {
return true;
}

private function getFullTableCacheKey() {
private function getFullTableCacheKey(): string {
return $this->cache->makeGlobalKey(
self::CACHE_CLASS,
$this->cacheKeyGroup
);
}

private function getSinglePropertyCacheKey( NumericPropertyId $propertyId ) {
private function getSinglePropertyCacheKey( NumericPropertyId $propertyId ): string {
return $this->cache->makeGlobalKey(
self::CACHE_CLASS,
$this->cacheKeyGroup,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function getLabel( EntityId $entityId ) {
return $label;
}

private function getTerm( EntityId $entityId, $languageCode, $termName = self::LABEL ) {
private function getTerm( EntityId $entityId, string $languageCode, string $termName = self::LABEL ): ?TermFallback {
$resolutionResult = $this->redirectResolvingRevisionLookup->lookupLatestRevisionResolvingRedirect( $entityId );
if ( $resolutionResult === null ) {
return null;
Expand Down
12 changes: 6 additions & 6 deletions lib/includes/Store/CachingPrefetchingTermLookup.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public function getDescription( EntityId $entityId, $languageCode ): ?string {
return $this->getTerm( $entityId, $languageCode, TermTypes::TYPE_DESCRIPTION );
}

private function getTerm( EntityId $entityId, string $languageCode, string $termType ) {
private function getTerm( EntityId $entityId, string $languageCode, string $termType ): ?string {
$cachedTerm = $this->getBufferedOrCachedEntry( $entityId, $termType, $languageCode );
if ( $cachedTerm !== null ) {
return $cachedTerm ?: null;
Expand Down Expand Up @@ -299,7 +299,7 @@ private function bufferAndCacheMissingTerm( EntityId $entityId, string $termType
);
}

private function getCacheKey( EntityId $id, string $language, string $termType ) {
private function getCacheKey( EntityId $id, string $language, string $termType ): ?string {
$resolutionResult = $this->redirectResolvingRevisionLookup->lookupLatestRevisionResolvingRedirect( $id );
if ( $resolutionResult === null ) {
return null;
Expand All @@ -320,7 +320,7 @@ private function getBufferedOrCachedEntry( EntityId $entityId, string $termType,
return $cacheKey === null ? null : $this->cache->get( $cacheKey );
}

private function getMultipleTermsByLanguageFromBuffer( EntityId $entityId, string $termType, array $languages ) {
private function getMultipleTermsByLanguageFromBuffer( EntityId $entityId, string $termType, array $languages ): array {
$terms = [];

// Lookup in termbuffer
Expand All @@ -334,7 +334,7 @@ private function getMultipleTermsByLanguageFromBuffer( EntityId $entityId, strin
return $terms;
}

private function getMultipleTermsByLanguageFromCache( EntityId $entityId, string $termType, array $languages ) {
private function getMultipleTermsByLanguageFromCache( EntityId $entityId, string $termType, array $languages ): array {
$terms = [];

$languagesToCacheKeys = [];
Expand All @@ -359,7 +359,7 @@ private function getMultipleTermsByLanguageFromCache( EntityId $entityId, string
return $terms;
}

private function getMultipleTermsByLanguageFromLookup( EntityId $entityId, string $termType, array $languages ) {
private function getMultipleTermsByLanguageFromLookup( EntityId $entityId, string $termType, array $languages ): array {
if ( $termType === TermTypes::TYPE_LABEL ) {
$freshTerms = $this->lookup->getLabels( $entityId, $languages );
} else {
Expand All @@ -377,7 +377,7 @@ private function getMultipleTermsByLanguageFromLookup( EntityId $entityId, strin
return $freshTerms;
}

private function getMultipleTermsByLanguage( EntityId $entityId, string $termType, array $languages ) {
private function getMultipleTermsByLanguage( EntityId $entityId, string $termType, array $languages ): array {
$terms = $this->getMultipleTermsByLanguageFromBuffer( $entityId, $termType, $languages );

// languages without prefetched terms
Expand Down
4 changes: 2 additions & 2 deletions lib/includes/Store/CachingPropertyInfoLookup.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,14 @@ function () use ( &$wanCacheHit, $fname ) {
return $this->propertyInfo;
}

private function getFullTableCacheKey() {
private function getFullTableCacheKey(): string {
return $this->cache->makeGlobalKey(
CacheAwarePropertyInfoStore::CACHE_CLASS,
$this->cacheKeyGroup
);
}

private function getSinglePropertyCacheKey( PropertyId $propertyId ) {
private function getSinglePropertyCacheKey( PropertyId $propertyId ): string {
return $this->cache->makeGlobalKey(
CacheAwarePropertyInfoStore::CACHE_CLASS,
$this->cacheKeyGroup,
Expand Down
2 changes: 1 addition & 1 deletion lib/includes/Store/LatestRevisionIdResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public static function concreteRevision( int $revisionId, string $revisionTimest
return $result;
}

private function __construct( $type ) {
private function __construct( string $type ) {
$this->type = $type;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ public function loadLatestRevisionIds( array $entityIds, $mode ) {
return $revisionIds;
}

private function doFetch( $mode ) {
private function doFetch( string $mode ) {
if ( !$this->toFetch ) {
return;
}
Expand Down
10 changes: 5 additions & 5 deletions lib/includes/Store/Sql/Terms/DatabaseTermInLangIdsAcquirer.php
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ private function mapToTextInLangIds(
private function acquireTextInLangIds(
array $langTextIds,
ReplicaPrimaryAwareRecordIdsAcquirer $textInLangIdsAcquirer
) {
): array {
$textInLangRecords = [];
foreach ( $langTextIds as $lang => $textIds ) {
foreach ( $textIds as $textId ) {
Expand Down Expand Up @@ -306,7 +306,7 @@ private function acquireTermInLangIdsInner(
array $typeTextInLangIds,
ReplicaPrimaryAwareRecordIdsAcquirer $termInLangIdsAcquirer,
array $idsToRestore = []
) {
): array {
$termInLangRecords = [];
foreach ( $typeTextInLangIds as $typeId => $textInLangIds ) {
foreach ( $textInLangIds as $textInLangId ) {
Expand Down Expand Up @@ -382,7 +382,7 @@ private function restoreCleanedUpIds( array $termsArray, array $termInLangIds =
private function mapTermsArrayToTermIds(
array $termsArray,
array $termInLangIdsToRestore = [],
$ignoreReplica = false
bool $ignoreReplica = false
): array {
$textIdsAcquirer = new ReplicaPrimaryAwareRecordIdsAcquirer(
$this->termsDb, 'wbt_text', 'wbx_id',
Expand All @@ -401,12 +401,12 @@ private function mapTermsArrayToTermIds(
return $this->mapToTermInLangIds( $termsArray, $termInLangIdsAcquirer, $termInLangIdsToRestore );
}

private function calcRecordHash( array $record ) {
private function calcRecordHash( array $record ): string {
ksort( $record );
return md5( serialize( $record ) );
}

private function filterUniqueRecords( array $records ) {
private function filterUniqueRecords( array $records ): array {
$uniqueRecords = [];
foreach ( $records as $record ) {
$recordHash = $this->calcRecordHash( $record );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use stdClass;
use Wikibase\Lib\Rdbms\TermsDomainDb;
use Wikibase\Lib\Store\Sql\Terms\Util\StatsMonitoring;
use Wikimedia\Rdbms\IReadableDatabase;
use Wikimedia\Rdbms\SelectQueryBuilder;

/**
Expand Down Expand Up @@ -166,19 +167,19 @@ private function addResultTerms( array &$terms, stdClass $row ) {
$terms[$type][$lang][] = $text;
}

private function lookupTypeName( $typeId ) {
private function lookupTypeName( string $typeId ): string {
$typeName = array_flip( TermTypeIds::TYPE_IDS )[$typeId] ?? null;
if ( $typeName === null ) {
throw new InvalidArgumentException( 'Unknown type ID: ' . $typeId );
}
return $typeName;
}

private function lookupTypeIds( array $typeNames ) {
private function lookupTypeIds( array $typeNames ): array {
return array_intersect_key( TermTypeIds::TYPE_IDS, array_flip( $typeNames ) );
}

private function getDbr() {
private function getDbr(): IReadableDatabase {
return $this->termsDb->getReadConnection();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public function getPrefetchedAliases( EntityId $entityId, $languageCode ) {
return $this->getFromBuffer( $entityId, TermTypes::TYPE_ALIAS, $languageCode ) ?? false;
}

private function getFromBuffer( EntityId $entityId, $termType, $languageCode ) {
private function getFromBuffer( EntityId $entityId, string $termType, string $languageCode ): ?array {
if ( !( $entityId instanceof Int32EntityId ) ) {
throw new InvalidArgumentException( "Not an Int32EntityId: " . $entityId->getSerialization() );
}
Expand Down
2 changes: 1 addition & 1 deletion lib/includes/TermIndexEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public static function compare( self $a, self $b ) {
return 0;
}

private static function getFieldValuesForCompare( self $entry ) {
private static function getFieldValuesForCompare( self $entry ): array {
return [
self::FIELD_ENTITY => $entry->getEntityId()->getSerialization(),
self::FIELD_TYPE => $entry->getTermType(),
Expand Down
2 changes: 1 addition & 1 deletion lib/packages/wikibase/changes/tests/TestChanges.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static function getEntityChangeFactory() {
return $factory;
}

private static function getInstances() {
private static function getInstances(): array {
/** @var EntityChange[] $changes */
static $changes = [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function deserialize( $serialization ) {
return $this->getDeserialized( $serialization );
}

private function getDeserialized( array $serialization ) {
private function getDeserialized( array $serialization ): Item {
$item = new Item();

$this->setIdFromSerialization( $serialization, $item );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function isDeserializerFor( $serialization ) {
return $this->isValidSerialization( $serialization );
}

private function isValidSerialization( $serialization ) {
private function isValidSerialization( $serialization ): bool {
return is_array( $serialization ) && array_key_exists( 'snaks', $serialization );
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private function getDeserialized( array $serialization ) {
);
}

private function getDeserializeBadges( array $serialization ) {
private function getDeserializeBadges( array $serialization ): array {
if ( !array_key_exists( 'badges', $serialization ) ) {
return [];
}
Expand All @@ -66,7 +66,7 @@ private function getDeserializeBadges( array $serialization ) {
return $badges;
}

private function deserializeItemId( $serialization ) {
private function deserializeItemId( $serialization ): ItemId {
$itemId = $this->entityIdDeserializer->deserialize( $serialization );

if ( !( $itemId instanceof ItemId ) ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function serialize( $object ) {
return $this->getSerialized( $object );
}

private function getSerialized( Property $property ) {
private function getSerialized( Property $property ): array {
$serialization = [
'type' => $property->getType(),
'datatype' => $property->getDataTypeId(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function serialize( $object ) {
return $this->getSerialized( $object );
}

private function getSerialized( ReferenceList $references ) {
private function getSerialized( ReferenceList $references ): array {
$serialization = [];

foreach ( $references as $reference ) {
Expand Down
Loading

0 comments on commit 29bebef

Please sign in to comment.