Thiemo Mättig (WMDE) has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/316349

Change subject: Replace method_exists with instanceof Int32EntityId
......................................................................

Replace method_exists with instanceof Int32EntityId

Since DataModel 6.1, which is already required for a while.

Change-Id: I11e124393492f8734ffd5bcc3be3967e83ba9360
---
M lib/includes/Store/Sql/TermSqlIndex.php
M lib/tests/phpunit/MockRepository.php
2 files changed, 9 insertions(+), 9 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/49/316349/1

diff --git a/lib/includes/Store/Sql/TermSqlIndex.php 
b/lib/includes/Store/Sql/TermSqlIndex.php
index fecaf09..d54ed84 100644
--- a/lib/includes/Store/Sql/TermSqlIndex.php
+++ b/lib/includes/Store/Sql/TermSqlIndex.php
@@ -9,6 +9,7 @@
 use Traversable;
 use Wikibase\DataModel\Entity\EntityDocument;
 use Wikibase\DataModel\Entity\EntityId;
+use Wikibase\DataModel\Entity\Int32EntityId;
 use Wikibase\DataModel\Entity\Item;
 use Wikibase\DataModel\Term\AliasesProvider;
 use Wikibase\DataModel\Term\AliasGroupList;
@@ -173,8 +174,9 @@
         * @return TermIndexEntry[]
         */
        public function getEntityTerms( EntityDocument $entity ) {
-               // FIXME: Introduce and use an Int32EntityId interface.
-               if ( !method_exists( $entity->getId(), 'getNumericId' ) ) {
+               $id = $entity->getId();
+
+               if ( !( $id instanceof Int32EntityId ) ) {
                        wfWarn( 'Entity type "' . $entity->getType() . '" does 
not implement getNumericId' );
                        return [];
                }
@@ -182,7 +184,7 @@
                $terms = [];
                $extraFields = [
                        'entityType' => $entity->getType(),
-                       'entityId' => $entity->getId()->getNumericId(),
+                       'entityId' => $id->getNumericId(),
                ];
 
                if ( $entity instanceof DescriptionsProvider ) {
diff --git a/lib/tests/phpunit/MockRepository.php 
b/lib/tests/phpunit/MockRepository.php
index 79f9612..173ed35 100644
--- a/lib/tests/phpunit/MockRepository.php
+++ b/lib/tests/phpunit/MockRepository.php
@@ -8,6 +8,7 @@
 use Wikibase\DataModel\Entity\EntityDocument;
 use Wikibase\DataModel\Entity\EntityId;
 use Wikibase\DataModel\Entity\EntityRedirect;
+use Wikibase\DataModel\Entity\Int32EntityId;
 use Wikibase\DataModel\Entity\Item;
 use Wikibase\DataModel\Entity\ItemId;
 use Wikibase\DataModel\Entity\Property;
@@ -620,14 +621,11 @@
        }
 
        private function updateMaxNumericId( EntityId $id ) {
-               if ( method_exists( $id, 'getNumericId' ) ) {
-                       $numericId = $id->getNumericId();
-               } else {
-                       // FIXME: This is a generic implementation of 
getNumericId for entities without.
-                       $numericId = (int)preg_replace( '/^\D+/', '', 
$id->getSerialization() );
+               if ( !( $id instanceof Int32EntityId ) ) {
+                       throw new StorageException( 'This class does not 
support non-numeric entity types' );
                }
 
-               $this->maxEntityId = max( $this->maxEntityId, $numericId );
+               $this->maxEntityId = max( $this->maxEntityId, 
$id->getNumericId() );
        }
 
        /**

-- 
To view, visit https://gerrit.wikimedia.org/r/316349
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I11e124393492f8734ffd5bcc3be3967e83ba9360
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to