jenkins-bot has submitted this change and it was merged.
Change subject: Introduce separate fields in TermIndexEntry instead of using
the array
......................................................................
Introduce separate fields in TermIndexEntry instead of using the array
Change-Id: Id17649b0885077b85a53c1602071c2650c79f2e8
---
M lib/includes/TermIndexEntry.php
1 file changed, 63 insertions(+), 30 deletions(-)
Approvals:
Thiemo Mättig (WMDE): Looks good to me, approved
Addshore: Looks good to me, approved
jenkins-bot: Verified
diff --git a/lib/includes/TermIndexEntry.php b/lib/includes/TermIndexEntry.php
index 5f53fd0..68d417c 100644
--- a/lib/includes/TermIndexEntry.php
+++ b/lib/includes/TermIndexEntry.php
@@ -29,11 +29,6 @@
const TYPE_ALIAS = 'alias';
const TYPE_DESCRIPTION = 'description';
- /**
- * @var array
- */
- private $fields = array();
-
private static $fieldNames = array(
'entityType',
'entityId',
@@ -41,6 +36,31 @@
'termLanguage',
'termText',
);
+
+ /**
+ * @var string|null, one of self::TYPE_* constants
+ */
+ private $termType;
+
+ /**
+ * @var string|null
+ */
+ private $termLanguage;
+
+ /**
+ * @var string|null
+ */
+ private $termText;
+
+ /**
+ * @var EntityId|null
+ */
+ private $entityId;
+
+ /**
+ * @var string|null
+ */
+ private $entityType;
/**
* @since 0.2
@@ -82,7 +102,7 @@
throw new MWException( 'Invalid term type provided' );
}
- $this->fields['termType'] = $termType;
+ $this->termType = $termType;
}
/**
@@ -91,7 +111,7 @@
* @return string|null
*/
public function getType() {
- return array_key_exists( 'termType', $this->fields ) ?
$this->fields['termType'] : null;
+ return $this->termType;
}
/**
@@ -104,7 +124,7 @@
throw new MWException( 'Language code can only be a
string' );
}
- $this->fields['termLanguage'] = $languageCode;
+ $this->termLanguage = $languageCode;
}
/**
@@ -113,7 +133,7 @@
* @return string|null
*/
public function getLanguage() {
- return array_key_exists( 'termLanguage', $this->fields ) ?
$this->fields['termLanguage'] : null;
+ return $this->termLanguage;
}
/**
@@ -126,7 +146,7 @@
throw new MWException( 'Term text code can only be a
string' );
}
- $this->fields['termText'] = $text;
+ $this->termText = $text;
}
/**
@@ -135,7 +155,7 @@
* @return string|null
*/
public function getText() {
- return array_key_exists( 'termText', $this->fields ) ?
$this->fields['termText'] : null;
+ return $this->termText;
}
/**
@@ -144,11 +164,11 @@
* @throws MWException
*/
private function setEntityType( $entityType ) {
- if ( isset( $this->fields['entityId'] ) ) {
- if ( $this->fields['entityId']->getEntityType() !==
$entityType ) {
+ if ( $this->entityId !== null ) {
+ if ( $this->entityId->getEntityType() !== $entityType )
{
throw new MWException(
'Cannot set entity type to "' .
$entityType . '"" as it does not match the type of entity id: "' .
-
$this->fields['entityId']->getEntityType() . '"'
+ $this->entityId->getEntityType() . '"'
);
}
return;
@@ -158,7 +178,7 @@
throw new MWException( 'Entity type code can only be a
string' );
}
- $this->fields['entityType'] = $entityType;
+ $this->entityType = $entityType;
}
/**
@@ -167,15 +187,15 @@
* @return string|null
*/
public function getEntityType() {
- if ( array_key_exists( 'entityId', $this->fields ) ) {
- return $this->fields['entityId']->getEntityType();
+ if ( $this->entityId !== null ) {
+ return $this->entityId->getEntityType();
}
- return array_key_exists( 'entityType', $this->fields ) ?
$this->fields['entityType'] : null;
+ return $this->entityType;
}
private function setEntityId( EntityId $id ) {
- $this->fields['entityId'] = $id;
- $this->fields['entityType'] = $id->getEntityType();
+ $this->entityId = $id;
+ $this->entityType = $id->getEntityType();
}
/**
@@ -185,7 +205,7 @@
* @return EntityId|null
*/
public function getEntityId() {
- return array_key_exists( 'entityId', $this->fields ) ?
$this->fields['entityId'] : null;
+ return $this->entityId;
}
/**
@@ -198,17 +218,19 @@
* @return int Returns 1 if $a is greater than $b, -1 if $b is greater
than $a, and 0 otherwise.
*/
public static function compare( self $a, self $b ) {
- foreach ( self::$fieldNames as $n ) {
- $exists = array_key_exists( $n, $a->fields );
+ $aValues = self::getFieldValuesForCompare( $a );
+ $bValues = self::getFieldValuesForCompare( $b );
- if ( $exists !== array_key_exists( $n, $b->fields ) ) {
- return $exists ? 1 : -1;
+ foreach ( self::$fieldNames as $n ) {
+ $aDefined = $aValues[$n] !== null;
+ $bDefined = $bValues[$n] !== null;
+
+ if ( $aDefined !== $bDefined ) {
+ return $aDefined ? 1 : -1;
}
- if ( $exists ) {
- $aValue = $n !== 'entityId' ? $a->fields[$n] :
$a->fields[$n]->getSerialization();
- $bValue = $n !== 'entityId' ? $b->fields[$n] :
$b->fields[$n]->getSerialization();
- if ( $aValue !== $bValue ) {
- return $aValue > $bValue ? 1 : -1;
+ if ( $aDefined ) {
+ if ( $aValues[$n] !== $bValues[$n] ) {
+ return $aValues[$n] > $bValues[$n] ? 1
: -1;
}
}
}
@@ -216,6 +238,17 @@
return 0;
}
+ private static function getFieldValuesForCompare( self $entry ) {
+ $entityId = $entry->getEntityId();
+ return [
+ 'entityType' => $entry->getEntityType(),
+ 'entityId' => $entityId !== null ?
$entityId->getSerialization() : null,
+ 'termType' => $entry->getType(),
+ 'termLanguage' => $entry->getLanguage(),
+ 'termText' => $entry->getText(),
+ ];
+ }
+
/**
* @return Term
* @throws MWException
--
To view, visit https://gerrit.wikimedia.org/r/323149
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Id17649b0885077b85a53c1602071c2650c79f2e8
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: WMDE-leszek <[email protected]>
Gerrit-Reviewer: Addshore <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits