jenkins-bot has submitted this change and it was merged.
Change subject: Code style improvements to SqlEntityInfoBuilder
......................................................................
Code style improvements to SqlEntityInfoBuilder
This is a direct follow-up to I1ae5245.
Change-Id: I626bb5a949ab90f51f5021e64a292de5e8d8a3e0
---
M lib/includes/store/sql/SqlEntityInfoBuilder.php
1 file changed, 21 insertions(+), 33 deletions(-)
Approvals:
WikidataJenkins: Verified
Daniel Kinzler: Looks good to me, approved
jenkins-bot: Verified
diff --git a/lib/includes/store/sql/SqlEntityInfoBuilder.php
b/lib/includes/store/sql/SqlEntityInfoBuilder.php
index b8c64b9..7ea4949 100644
--- a/lib/includes/store/sql/SqlEntityInfoBuilder.php
+++ b/lib/includes/store/sql/SqlEntityInfoBuilder.php
@@ -2,18 +2,17 @@
namespace Wikibase\Lib\Store\Sql;
+use DBAccessBase;
use InvalidArgumentException;
-use OutOfBoundsException;
use ResultWrapper;
use RuntimeException;
use Wikibase\DataModel\Entity\BasicEntityIdParser;
+use Wikibase\DataModel\Entity\EntityId;
use Wikibase\DataModel\Entity\EntityIdParser;
use Wikibase\DataModel\Entity\EntityIdParsingException;
+use Wikibase\DataModel\Entity\Property;
use Wikibase\DataModel\Entity\PropertyId;
-use Wikibase\DataModel;
-use Wikibase\EntityId;
use Wikibase\Lib\Store\EntityInfoBuilder;
-use Wikibase\Property;
/**
* Class EntityInfoBuilder implementation relying on database access.
@@ -23,7 +22,7 @@
* @license GPL 2+
* @author Daniel Kinzler
*/
-class SqlEntityInfoBuilder extends \DBAccessBase implements EntityInfoBuilder {
+class SqlEntityInfoBuilder extends DBAccessBase implements EntityInfoBuilder {
/**
* Maps term types to fields used for lists of these terms in entity
serializations.
@@ -39,17 +38,17 @@
/**
* @var string The name of the database table holding terms.
*/
- protected $termTable;
+ private $termTable;
/**
* @var string The name of the database table holding property info.
*/
- protected $propertyInfoTable;
+ private $propertyInfoTable;
/**
* @var string The name of the database table connecting entities to
pages.
*/
- protected $entityPerPageTable;
+ private $entityPerPageTable;
/**
* @var bool
@@ -150,7 +149,7 @@
*/
private function setEntityIds( array $ids ) {
if ( $this->entityIds !== null ) {
- throw new \RuntimeException( 'EntityIds have already
been initialized' );
+ throw new RuntimeException( 'EntityIds have already
been initialized' );
}
$this->entityIds = array();
@@ -158,16 +157,7 @@
$this->numericIdsByType = array();
foreach ( $ids as $id ) {
- $key = $id->getSerialization();
- $type = $id->getEntityType();
-
- $this->entityInfo[$key] = array(
- 'id' => $key,
- 'type' => $type,
- );
-
- $this->numericIdsByType[$type][$key] =
$id->getNumericId();
- $this->entityIds[$key] = $id;
+ $this->updateEntityInfo( $id );
}
}
@@ -215,7 +205,7 @@
}
// Copy the record for the old key to the target key.
- $this->initRecord( $targetKey, $this->entityInfo[$idString] );
+ $this->initEntityInfo( $targetKey, $this->entityInfo[$idString]
);
// Remove the original entry for the old key.
$this->unsetKey( $idString );
@@ -224,7 +214,7 @@
$this->createEntityInfoReference( $idString,
$this->entityInfo[$targetKey] );
// From now on, use the target ID in the record and for
database queries.
- $this->forceEntityId( $targetKey, $targetId );
+ $this->updateEntityInfo( $targetId );
}
/**
@@ -236,7 +226,7 @@
* @param array $record
*/
private function createEntityInfoReference( $key, array &$record ) {
- $this->entityInfo[$key] = & $record;
+ $this->entityInfo[$key] = &$record;
}
/**
@@ -262,30 +252,28 @@
* @param string $key
* @param array $record
*/
- private function initRecord( $key, array $record ) {
+ private function initEntityInfo( $key, array $record ) {
if ( !isset( $this->entityInfo[$key] ) ) {
$this->entityInfo[$key] = $record;
}
}
/**
- * Forces the EntityId associated with the given key.
- * May be used on entries for ids that are redirected, when the
- * actual ID differs from the original (redirected) entity id.
- *
- * This updates the $entityInfo structure, and makes the ID
+ * Updates the $entityInfo structure and makes the ID
* available via the $numericIdsByType and $entityIds caches.
*
- * @param string $key
* @param EntityId $id
*/
- private function forceEntityId( $key, EntityId $id ) {
- //NOTE: we assume that the type of entity never changes.
+ private function updateEntityInfo( EntityId $id ) {
$type = $id->getEntityType();
+ $key = $id->getSerialization();
- $this->numericIdsByType[$type][$key] = $id->getNumericId();
+ // NOTE: we assume that the type of entity never changes.
+ $this->initEntityInfo( $key, array( 'type' => $type ) );
+
$this->entityIds[$key] = $id;
$this->entityInfo[$key]['id'] = $key;
+ $this->numericIdsByType[$type][$key] = $id->getNumericId();
}
/**
@@ -392,7 +380,7 @@
*
* @param ResultWrapper $dbResult
*
- * @throws \InvalidArgumentException
+ * @throws InvalidArgumentException
*/
private function injectTerms( ResultWrapper $dbResult ) {
foreach ( $dbResult as $row ) {
--
To view, visit https://gerrit.wikimedia.org/r/146179
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I626bb5a949ab90f51f5021e64a292de5e8d8a3e0
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Hoo man <[email protected]>
Gerrit-Reviewer: Jeroen De Dauw <[email protected]>
Gerrit-Reviewer: WikidataJenkins <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits