Jeroen De Dauw has uploaded a new change for review.
https://gerrit.wikimedia.org/r/81538
Change subject: Use LegacyIdInterpreter in EntityId to get rid of duplication
......................................................................
Use LegacyIdInterpreter in EntityId to get rid of duplication
Change-Id: I894496a761cf0a2b0f9bed269aee776b233e1136
---
M DataModel/Entity/EntityId.php
M DataModel/Internal/LegacyIdInterpreter.php
2 files changed, 9 insertions(+), 17 deletions(-)
git pull
ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikibaseDataModel
refs/changes/38/81538/1
diff --git a/DataModel/Entity/EntityId.php b/DataModel/Entity/EntityId.php
index 478c31d..fd16a61 100644
--- a/DataModel/Entity/EntityId.php
+++ b/DataModel/Entity/EntityId.php
@@ -5,6 +5,7 @@
use Comparable;
use InvalidArgumentException;
use Serializable;
+use Wikibase\DataModel\Internal\LegacyIdInterpreter;
/**
* @since 0.5
@@ -61,19 +62,9 @@
$this->serialization = strtoupper( $idSerialization );
}
- private function replaceNumericIdArgument( $idSerialization ) {
- $entityTypes = array(
- 'item' => 'q',
- 'property' => 'p',
- );
-
- if ( !array_key_exists( $this->entityType, $entityTypes ) ) {
- throw new InvalidArgumentException(
- 'Provided a numeric id (deprecated) for an
entity type that never supported this'
- );
- }
-
- return $entityTypes[$this->entityType] .
(string)$idSerialization;
+ private function replaceNumericIdArgument( $numericId ) {
+ return LegacyIdInterpreter::newIdFromTypeAndNumber(
$this->entityType, $numericId )
+ ->getSerialization();
}
/**
diff --git a/DataModel/Internal/LegacyIdInterpreter.php
b/DataModel/Internal/LegacyIdInterpreter.php
index 1cb6087..195c724 100644
--- a/DataModel/Internal/LegacyIdInterpreter.php
+++ b/DataModel/Internal/LegacyIdInterpreter.php
@@ -4,6 +4,7 @@
use InvalidArgumentException;
use Wikibase\DataModel\Entity\BasicEntityIdParser;
+use Wikibase\DataModel\Entity\EntityId;
/**
* Turns legacy entity id serializations consisting of entity type + numeric id
@@ -25,7 +26,7 @@
* @param string $entityType
* @param int|string $numericId
*
- * @return mixed
+ * @return EntityId
*/
public static function newIdFromTypeAndNumber( $entityType, $numericId
) {
$idParser = new BasicEntityIdParser();
@@ -43,12 +44,12 @@
*/
protected static function constructSerialization( $entityType,
$numericId ) {
$entityTypes = array(
- 'item' => 'q',
- 'property' => 'p',
+ 'item' => 'Q',
+ 'property' => 'P',
);
if ( !array_key_exists( $entityType, $entityTypes ) ) {
- throw new InvalidArgumentException( 'Unsupported entity
type' );
+ throw new InvalidArgumentException( 'Provided a numeric
id (deprecated) for an entity type that never supported this' );
}
return $entityTypes[$entityType] . (string)$numericId;
--
To view, visit https://gerrit.wikimedia.org/r/81538
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I894496a761cf0a2b0f9bed269aee776b233e1136
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/WikibaseDataModel
Gerrit-Branch: master
Gerrit-Owner: Jeroen De Dauw <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits