[MediaWiki-commits] [Gerrit] Consolidate duplicate code in UsageAccumulator classes - change (mediawiki...Wikibase)
jenkins-bot has submitted this change and it was merged. Change subject: Consolidate duplicate code in UsageAccumulator classes .. Consolidate duplicate code in UsageAccumulator classes An other possibility is to keep the interface as it is and add a base class with the shared methods. But this means the base class can have *more* methods than the interface and I think this is not a good idea. Therefor I'm proposing this solution. Change-Id: I3902dfc8e493066fcc9a0337247885884d25d909 --- M client/includes/Usage/HashUsageAccumulator.php M client/includes/Usage/ParserOutputUsageAccumulator.php M client/includes/Usage/UsageAccumulator.php M client/tests/phpunit/includes/Hooks/DataUpdateHookHandlersTest.php 4 files changed, 65 insertions(+), 161 deletions(-) Approvals: Daniel Kinzler: Looks good to me, approved jenkins-bot: Verified Objections: Adrian Lang: There's a problem with this change, please improve diff --git a/client/includes/Usage/HashUsageAccumulator.php b/client/includes/Usage/HashUsageAccumulator.php index e819b92..d328a2d 100644 --- a/client/includes/Usage/HashUsageAccumulator.php +++ b/client/includes/Usage/HashUsageAccumulator.php @@ -2,11 +2,6 @@ namespace Wikibase\Client\Usage; -use Wikibase\DataModel\Entity\EntityId; -use Wikibase\DataModel\Entity\EntityIdValue; -use Wikibase\DataModel\Snak\PropertyValueSnak; -use Wikibase\DataModel\Snak\Snak; - /** * This implementation of the UsageAccumulator interface simply wraps * an array containing the usage information. @@ -14,7 +9,7 @@ * @license GPL 2+ * @author Daniel Kinzler */ -class HashUsageAccumulator implements UsageAccumulator { +class HashUsageAccumulator extends UsageAccumulator { /** * @var EntityUsage[] @@ -22,87 +17,22 @@ private $usages = array(); /** -* Registers usage of the given aspect of the given entity. +* @see UsageAccumulator::addUsage * -* @param EntityId $id -* @param string $aspect Use the EntityUsage::XXX_USAGE constants. +* @param EntityUsage $usage */ - public function addUsage( EntityId $id, $aspect ) { - $usage = new EntityUsage( $id, $aspect ); - + public function addUsage( EntityUsage $usage ) { $key = $usage->getIdentityString(); $this->usages[$key] = $usage; } /** -* @see UsageAccumulator::getUsage() +* @see UsageAccumulator::getUsage * * @return EntityUsage[] */ public function getUsages() { return $this->usages; - } - - /** -* @see UsageAccumulator::addLabelUsageForSnaks -* -* @param Snak[] $snaks -*/ - public function addLabelUsageForSnaks( array $snaks ) { - foreach ( $snaks as $snak ) { - if ( $snak instanceof PropertyValueSnak ) { - $value = $snak->getDataValue(); - - if ( $value instanceof EntityIdValue ) { - $this->addLabelUsage( $value->getEntityId() ); - } - } - } - } - - /** -* @see UsageAccumulator::addLabelUsage -* -* @param EntityId $id -*/ - public function addLabelUsage( EntityId $id ) { - $this->addUsage( $id, EntityUsage::LABEL_USAGE ); - } - - /** -* @see UsageAccumulator::addTitleUsage -* -* @param EntityId $id -*/ - public function addTitleUsage( EntityId $id ) { - $this->addUsage( $id, EntityUsage::TITLE_USAGE ); - } - - /** -* @see UsageAccumulator::addSitelinksUsage -* -* @param EntityId $id -*/ - public function addSiteLinksUsage( EntityId $id ) { - $this->addUsage( $id, EntityUsage::SITELINK_USAGE ); - } - - /** -* @see UsageAccumulator::addOtherUsage -* -* @param EntityId $id -*/ - public function addOtherUsage( EntityId $id ) { - $this->addUsage( $id, EntityUsage::OTHER_USAGE ); - } - - /** -* @see UsageAccumulator::addAllUsage -* -* @param EntityId $id -*/ - public function addAllUsage( EntityId $id ) { - $this->addUsage( $id, EntityUsage::ALL_USAGE ); } } diff --git a/client/includes/Usage/ParserOutputUsageAccumulator.php b/client/includes/Usage/ParserOutputUsageAccumulator.php index d89a57f..33c1b7a 100644 --- a/client/includes/Usage/ParserOutputUsageAccumulator.php +++ b/client/includes/Usage/ParserOutputUsageAccumulator.php @@ -3,10 +3,6 @@ namespace Wikibase\Client\Usage; use ParserOutput; -use Wikibase\DataModel\Entity\EntityId; -use Wikibase\DataModel\Entity\EntityIdValu
[MediaWiki-commits] [Gerrit] Consolidate duplicate code in UsageAccumulator classes - change (mediawiki...Wikibase)
Thiemo Mättig (WMDE) has uploaded a new change for review. https://gerrit.wikimedia.org/r/191336 Change subject: Consolidate duplicate code in UsageAccumulator classes .. Consolidate duplicate code in UsageAccumulator classes An other possibility is to keep the interface as it is and add a base class with the shared methods. But this means the base class can have *more* methods than the interface and I think this is not a good idea. Therefor I'm proposing this solution. Change-Id: I3902dfc8e493066fcc9a0337247885884d25d909 --- M client/includes/Usage/HashUsageAccumulator.php M client/includes/Usage/ParserOutputUsageAccumulator.php M client/includes/Usage/UsageAccumulator.php M client/tests/phpunit/includes/Hooks/DataUpdateHookHandlersTest.php 4 files changed, 62 insertions(+), 165 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/36/191336/1 diff --git a/client/includes/Usage/HashUsageAccumulator.php b/client/includes/Usage/HashUsageAccumulator.php index b68ce00..28e6406 100644 --- a/client/includes/Usage/HashUsageAccumulator.php +++ b/client/includes/Usage/HashUsageAccumulator.php @@ -3,9 +3,6 @@ namespace Wikibase\Client\Usage; use Wikibase\DataModel\Entity\EntityId; -use Wikibase\DataModel\Entity\EntityIdValue; -use Wikibase\DataModel\Snak\PropertyValueSnak; -use Wikibase\DataModel\Snak\Snak; /** * This implementation of the UsageAccumulator interface simply wraps @@ -14,7 +11,7 @@ * @license GPL 2+ * @author Daniel Kinzler */ -class HashUsageAccumulator implements UsageAccumulator { +class HashUsageAccumulator extends UsageAccumulator { /** * @var EntityUsage[] @@ -22,87 +19,22 @@ private $usages = array(); /** -* Registers usage of the given aspect of the given entity. +* @see UsageAccumulator::addUsage * -* @param EntityId $id -* @param string $aspect Use the EntityUsage::XXX_USAGE constants. +* @param EntityUsage $usage */ - public function addUsage( EntityId $id, $aspect ) { - $usage = new EntityUsage( $id, $aspect ); - + public function addUsage( EntityUsage $usage ) { $key = $usage->getIdentityString(); $this->usages[$key] = $usage; } /** -* @see UsageAccumulator::getUsage() +* @see UsageAccumulator::getUsage * * @return EntityUsage[] */ public function getUsages() { return $this->usages; - } - - /** -* @see UsageAccumulator::addLabelUsage -* -* @param EntityId $id -*/ - public function addLabelUsage( EntityId $id ) { - $this->addUsage( $id, EntityUsage::LABEL_USAGE ); - } - - /** -* @see UsageAccumulator::addLabelUsageForSnaks -* -* @param Snak[] $snaks -*/ - public function addLabelUsageForSnaks( array $snaks ) { - foreach ( $snaks as $snak ) { - if ( $snak instanceof PropertyValueSnak ) { - $value = $snak->getDataValue(); - - if ( $value instanceof EntityIdValue ) { - $this->addLabelUsage( $value->getEntityId() ); - } - } - } - } - - /** -* @see UsageAccumulator::addTitleUsage -* -* @param EntityId $id -*/ - public function addTitleUsage( EntityId $id ) { - $this->addUsage( $id, EntityUsage::TITLE_USAGE ); - } - - /** -* @see UsageAccumulator::addSitelinksUsage -* -* @param EntityId $id -*/ - public function addSiteLinksUsage( EntityId $id ) { - $this->addUsage( $id, EntityUsage::SITELINK_USAGE ); - } - - /** -* @see UsageAccumulator::addOtherUsage -* -* @param EntityId $id -*/ - public function addOtherUsage( EntityId $id ) { - $this->addUsage( $id, EntityUsage::OTHER_USAGE ); - } - - /** -* @see UsageAccumulator::addAllUsage -* -* @param EntityId $id -*/ - public function addAllUsage( EntityId $id ) { - $this->addUsage( $id, EntityUsage::ALL_USAGE ); } } diff --git a/client/includes/Usage/ParserOutputUsageAccumulator.php b/client/includes/Usage/ParserOutputUsageAccumulator.php index 0ddc49e..e66c9c4 100644 --- a/client/includes/Usage/ParserOutputUsageAccumulator.php +++ b/client/includes/Usage/ParserOutputUsageAccumulator.php @@ -4,9 +4,6 @@ use ParserOutput; use Wikibase\DataModel\Entity\EntityId; -use Wikibase\DataModel\Entity\EntityIdValue; -use Wikibase\DataModel\Snak\PropertyValueSnak; -use Wikibase\DataModel\Snak\Snak; /** * This