[MediaWiki-commits] [Gerrit] mediawiki...Wikibase[master]: Replace method_exists with instanceof Int32EntityId

2016-10-18 Thread jenkins-bot (Code Review)
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) 
Gerrit-Reviewer: Aude 
Gerrit-Reviewer: Hoo man 
Gerrit-Reviewer: Thiemo Mättig (WMDE) 
Gerrit-Reviewer: jenkins-bot <>

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


[MediaWiki-commits] [Gerrit] mediawiki...Wikibase[master]: Replace method_exists with instanceof Int32EntityId

2016-10-17 Thread WMDE
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) 

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