Thiemo Mättig (WMDE) has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/177234

Change subject: Use switch in EntityIdTitleFormatters
......................................................................

Use switch in EntityIdTitleFormatters

If it looks like a switch why not use a switch?

Change-Id: If5304b5e309ecf28a45d71c1e3839d487c76c55f
---
M lib/tests/phpunit/formatters/EntityIdLinkFormatterTest.php
M lib/tests/phpunit/formatters/EntityIdTitleFormatterTest.php
M repo/includes/store/sql/ItemsPerSiteBuilder.php
3 files changed, 17 insertions(+), 19 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase 
refs/changes/34/177234/1

diff --git a/lib/tests/phpunit/formatters/EntityIdLinkFormatterTest.php 
b/lib/tests/phpunit/formatters/EntityIdLinkFormatterTest.php
index 4c5ecc9..357c914 100644
--- a/lib/tests/phpunit/formatters/EntityIdLinkFormatterTest.php
+++ b/lib/tests/phpunit/formatters/EntityIdLinkFormatterTest.php
@@ -58,16 +58,15 @@
                $this->assertEquals( $expected, $actual );
        }
 
-       public function getTitleForId( EntityId $id ) {
-               if ( $id->getEntityType() === Item::ENTITY_TYPE ) {
-                       $name = 'ITEM-TEST--' . $id->getSerialization();
-               } elseif ( $id->getEntityType() === Property::ENTITY_TYPE ) {
-                       $name = 'PROPERTY-TEST--' . $id->getSerialization();
-               } else {
-                       throw new LogicException( "oops!" );
+       public function getTitleForId( EntityId $entityId ) {
+               switch ( $entityId->getEntityType() ) {
+                       case Item::ENTITY_TYPE:
+                               return Title::makeTitle( NS_MAIN, 'ITEM-TEST--' 
. $entityId->getSerialization() );
+                       case Property::ENTITY_TYPE:
+                               return Title::makeTitle( NS_MAIN, 
'PROPERTY-TEST--' . $entityId->getSerialization() );
+                       default:
+                               throw new LogicException( "oops!" );
                }
-
-               return Title::makeTitle( NS_MAIN, $name );
        }
 
        protected function newEntityIdLinkFormatter() {
diff --git a/lib/tests/phpunit/formatters/EntityIdTitleFormatterTest.php 
b/lib/tests/phpunit/formatters/EntityIdTitleFormatterTest.php
index 970adf0..6b14262 100644
--- a/lib/tests/phpunit/formatters/EntityIdTitleFormatterTest.php
+++ b/lib/tests/phpunit/formatters/EntityIdTitleFormatterTest.php
@@ -58,16 +58,15 @@
                $this->assertEquals( $expected, $actual );
        }
 
-       public function getTitleForId( EntityId $id ) {
-               if ( $id->getEntityType() === Item::ENTITY_TYPE ) {
-                       $name = 'ITEM-TEST--' . $id->getSerialization();
-               } elseif ( $id->getEntityType() === Property::ENTITY_TYPE ) {
-                       $name = 'PROPERTY-TEST--' . $id->getSerialization();
-               } else {
-                       throw new LogicException( "oops!" );
+       public function getTitleForId( EntityId $entityId ) {
+               switch ( $entityId->getEntityType() ) {
+                       case Item::ENTITY_TYPE:
+                               return Title::makeTitle( NS_MAIN, 'ITEM-TEST--' 
. $entityId->getSerialization() );
+                       case Property::ENTITY_TYPE:
+                               return Title::makeTitle( NS_MAIN, 
'PROPERTY-TEST--' . $entityId->getSerialization() );
+                       default:
+                               throw new LogicException( "oops!" );
                }
-
-               return Title::makeTitle( NS_MAIN, $name );
        }
 
        protected function newEntityIdTitleFormatter() {
diff --git a/repo/includes/store/sql/ItemsPerSiteBuilder.php 
b/repo/includes/store/sql/ItemsPerSiteBuilder.php
index bc789f9..aed1b17 100644
--- a/repo/includes/store/sql/ItemsPerSiteBuilder.php
+++ b/repo/includes/store/sql/ItemsPerSiteBuilder.php
@@ -2,6 +2,7 @@
 
 namespace Wikibase\Repo\Store\SQL;
 
+use Wikibase\DataModel\Entity\EntityId;
 use Wikibase\DataModel\Entity\Item;
 use Wikibase\Lib\Reporting\MessageReporter;
 use Wikibase\Lib\Store\EntityLookup;
@@ -92,7 +93,6 @@
        private function rebuildSiteLinks( array $entityIds ) {
                $c = 0;
                foreach ( $entityIds as $entityId ) {
-                       /* @var $entityId EntityId */
                        if ( !$entityId->getEntityType() === Item::ENTITY_TYPE 
) {
                                // Just in case someone is using a 
EntityIdPager which doesn't filter non-Items
                                continue;

-- 
To view, visit https://gerrit.wikimedia.org/r/177234
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: If5304b5e309ecf28a45d71c1e3839d487c76c55f
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de>

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

Reply via email to