[MediaWiki-commits] [Gerrit] Rework and clean up TermIndex interfaces - change (mediawiki...Wikibase)
jenkins-bot has submitted this change and it was merged. Change subject: Rework and clean up TermIndex interfaces .. Rework and clean up TermIndex interfaces This is a direct follow up to all my comments in Ie0d92ae. Main reason for this patch is the removal of the redundant $entityType parameter. DEPLOYMENT: Needs Version 2.0.5 of PropertySuggester, see https://github.com/Wikidata-lib/PropertySuggester/pull/115 Change-Id: Ibec48cf6b33017336f73463e608b88c09e718993 --- M client/includes/api/PageTerms.php M client/tests/phpunit/includes/api/PageTermsTest.php M lib/includes/store/BufferingTermLookup.php M lib/includes/store/TermIndex.php M lib/includes/store/sql/TermSqlIndex.php M lib/tests/phpunit/store/MockTermIndex.php M lib/tests/phpunit/store/TermIndexTest.php M repo/includes/api/SearchEntities.php 8 files changed, 98 insertions(+), 98 deletions(-) Approvals: Daniel Kinzler: Looks good to me, approved jenkins-bot: Verified diff --git a/client/includes/api/PageTerms.php b/client/includes/api/PageTerms.php index 39329d4..da7d169 100644 --- a/client/includes/api/PageTerms.php +++ b/client/includes/api/PageTerms.php @@ -8,8 +8,8 @@ use ApiResult; use InvalidArgumentException; use Title; -use Wikibase\Store\EntityIdLookup; use Wikibase\DataModel\Entity\EntityId; +use Wikibase\Store\EntityIdLookup; use Wikibase\Term; use Wikibase\TermIndex; @@ -108,10 +108,10 @@ $entityIdGroups = $this->splitPageEntityMapByType( $entityIds ); $terms = array(); - foreach ( $entityIdGroups as $entityType => $entityIds ) { + foreach ( $entityIdGroups as $entityIds ) { $terms = array_merge( $terms, - $this->termIndex->getTermsOfEntities( $entityIds, $entityType, $termTypes, $languageCodes ) + $this->termIndex->getTermsOfEntities( $entityIds, $termTypes, $languageCodes ) ); } diff --git a/client/tests/phpunit/includes/api/PageTermsTest.php b/client/tests/phpunit/includes/api/PageTermsTest.php index 3b8d3c0..fe6124f 100644 --- a/client/tests/phpunit/includes/api/PageTermsTest.php +++ b/client/tests/phpunit/includes/api/PageTermsTest.php @@ -108,7 +108,7 @@ } /** -* @param array $terms +* @param array[] $terms * * @return TermIndex */ @@ -121,14 +121,14 @@ $termObjectsByEntityId[$key] = $this->makeTermsFromGroups( $entityId, $termGroups ); } - $this_ = $this; + $self = $this; $termIndex = $this->getMock( 'Wikibase\TermIndex' ); $termIndex->expects( $this->any() ) ->method( 'getTermsOfEntities' ) ->will( $this->returnCallback( - function ( array $entityIds, $entityType, $termTypes = null, $languages = null ) use( $termObjectsByEntityId, $this_ ) { - return $this_->getTermsOfEntities( $termObjectsByEntityId, $entityIds, $entityType, $termTypes, $languages ); + function( array $entityIds, array $termTypes = null, array $languagesCodes = null ) use ( $termObjectsByEntityId, $self ) { + return $self->getTermsOfEntities( $termObjectsByEntityId, $entityIds, $termTypes, $languagesCodes ); } ) ); @@ -139,14 +139,14 @@ * @note Public only because older PHP versions don't allow it to be called * from a closure otherwise. * -* @param array $termObjectsByEntityId +* @param array[] $termObjectsByEntityId * @param EntityId[] $entityIds -* @param string $entityType -* @param string|null $language +* @param string[]|null $termTypes +* @param string[]|null $languageCodes * * @return Term[] */ - public function getTermsOfEntities( $termObjectsByEntityId, $entityIds, $entityType, $termTypes, $languages ) { + public function getTermsOfEntities( array $termObjectsByEntityId, array $entityIds, array $termTypes = null, array $languageCodes = null ) { $result = array(); foreach ( $entityIds as $id ) { @@ -158,11 +158,9 @@ /** @var Term $term */ foreach ( $termObjectsByEntityId[$key] as $term ) { - if ( $languages !== null && !in_array( $term->getLanguage(), $languages ) ) { - continue; - } - - if ( $termTypes !== null && !in_array( $term->getType(), $termTypes ) ) { + if ( ( i
[MediaWiki-commits] [Gerrit] Rework and clean up TermIndex interfaces - change (mediawiki...Wikibase)
Thiemo Mättig (WMDE) has uploaded a new change for review. https://gerrit.wikimedia.org/r/179931 Change subject: Rework and clean up TermIndex interfaces .. Rework and clean up TermIndex interfaces This is a direct follow up to all my comments in Ie0d92ae. Main reason for this patch is the removal of the redundant $entityType parameter. Please note that both patches (Ie0d92ae and this one) will cause breaking changes in PropertySuggester! Change-Id: Ibec48cf6b33017336f73463e608b88c09e718993 --- M client/includes/api/PageTerms.php M client/tests/phpunit/includes/api/PageTermsTest.php M lib/includes/store/TermIndex.php M lib/includes/store/sql/TermSqlIndex.php M lib/tests/phpunit/store/MockTermIndex.php M lib/tests/phpunit/store/TermIndexTest.php M repo/includes/api/SearchEntities.php 7 files changed, 93 insertions(+), 97 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/31/179931/1 diff --git a/client/includes/api/PageTerms.php b/client/includes/api/PageTerms.php index 58c252b..c77530a 100644 --- a/client/includes/api/PageTerms.php +++ b/client/includes/api/PageTerms.php @@ -74,7 +74,7 @@ $pagesToEntityIds = $this->getEntityIdsForTitles( $titles, $continue ); $entityToPageMap = $this->getEntityToPageMap( $pagesToEntityIds ); - $terms = $this->getTermsOfEntities( $pagesToEntityIds, $languageCode, $params['terms'] ); + $terms = $this->getTermsOfEntities( $pagesToEntityIds, $params['terms'], $languageCode ); $termGroups = $this->groupTermsByPageAndType( $entityToPageMap, $terms ); @@ -99,19 +99,19 @@ /** * @param EntityID[] $entityIds -* @param string $languageCode * @param string[]|null $termTypes +* @param string $languageCode * * @return Term[] */ - private function getTermsOfEntities( array $entityIds, $languageCode, array $termTypes = null ) { + private function getTermsOfEntities( array $entityIds, array $termTypes = null, $languageCode ) { $entityIdGroups = $this->splitPageEntityMapByType( $entityIds ); $terms = array(); - foreach ( $entityIdGroups as $entityType => $entityIds ) { + foreach ( $entityIdGroups as $entityIds ) { $terms = array_merge( $terms, - $this->termIndex->getTermsOfEntities( $entityIds, $entityType, $termTypes, array( $languageCode ) ) + $this->termIndex->getTermsOfEntities( $entityIds, $termTypes, array( $languageCode ) ) ); } diff --git a/client/tests/phpunit/includes/api/PageTermsTest.php b/client/tests/phpunit/includes/api/PageTermsTest.php index 487dc2b..2638cda 100644 --- a/client/tests/phpunit/includes/api/PageTermsTest.php +++ b/client/tests/phpunit/includes/api/PageTermsTest.php @@ -108,7 +108,7 @@ } /** -* @param array $terms +* @param array[] $terms * * @return TermIndex */ @@ -121,14 +121,14 @@ $termObjectsByEntityId[$key] = $this->makeTermsFromGroups( $entityId, $termGroups ); } - $this_ = $this; + $self = $this; $termIndex = $this->getMock( 'Wikibase\TermIndex' ); $termIndex->expects( $this->any() ) ->method( 'getTermsOfEntities' ) ->will( $this->returnCallback( - function ( array $entityIds, $entityType, $termTypes = null, $languages = null ) use( $termObjectsByEntityId, $this_ ) { - return $this_->getTermsOfEntities( $termObjectsByEntityId, $entityIds, $entityType, $termTypes, $languages ); + function( array $entityIds, array $termTypes = null, array $languagesCodes = null ) use ( $termObjectsByEntityId, $self ) { + return $self->getTermsOfEntities( $termObjectsByEntityId, $entityIds, $termTypes, $languagesCodes ); } ) ); @@ -139,14 +139,14 @@ * @note Public only because older PHP versions don't allow it to be called * from a closure otherwise. * -* @param array $termObjectsByEntityId +* @param array[] $termObjectsByEntityId * @param EntityId[] $entityIds -* @param string $entityType -* @param string|null $language +* @param string[]|null $termTypes +* @param string[]|null $languageCodes * * @return Term[] */ - public function getTermsOfEntities( $termObjectsByEntityId, $entityIds, $entityType, $termTypes, $languages ) { +