jenkins-bot has submitted this change and it was merged.

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, 18 insertions(+), 10 deletions(-)

Approvals:
  Hoo man: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/lib/includes/Store/Sql/TermSqlIndex.php 
b/lib/includes/Store/Sql/TermSqlIndex.php
index fecaf09..b8e8ce5 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,16 +174,17 @@
         * @return TermIndexEntry[]
         */
        public function getEntityTerms( EntityDocument $entity ) {
-               // FIXME: Introduce and use an Int32EntityId interface.
-               if ( !method_exists( $entity->getId(), 'getNumericId' ) ) {
-                       wfWarn( 'Entity type "' . $entity->getType() . '" does 
not implement getNumericId' );
+               $id = $entity->getId();
+
+               if ( !( $id instanceof Int32EntityId ) ) {
+                       wfWarn( 'Entity type "' . $entity->getType() . '" does 
not implement Int32EntityId' );
                        return [];
                }
 
                $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..a8d56d4 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;
@@ -239,6 +240,7 @@
         * @param int|string $timestamp
         * @param User|string|null $user
         *
+        * @throws StorageException
         * @return EntityRevision
         */
        public function putEntity( EntityDocument $entity, $revisionId = 0, 
$timestamp = 0, $user = null ) {
@@ -299,6 +301,8 @@
         * @param EntityRedirect $redirect
         * @param int $revisionId
         * @param string|int $timestamp
+        *
+        * @throws StorageException
         */
        public function putRedirect( EntityRedirect $redirect, $revisionId = 0, 
$timestamp = 0 ) {
                $key = $redirect->getEntityId()->getSerialization();
@@ -619,15 +623,17 @@
                return isset( $this->watchlist[ $user->getName() ][ 
$entityId->getSerialization() ] );
        }
 
+       /**
+        * @param EntityId $id
+        *
+        * @throws StorageException
+        */
        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: merged
Gerrit-Change-Id: I11e124393492f8734ffd5bcc3be3967e83ba9360
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de>
Gerrit-Reviewer: Aude <aude.w...@gmail.com>
Gerrit-Reviewer: Hoo man <h...@online.de>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to