Adrian Lang has uploaded a new change for review.

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

Change subject: Simplify EntityIdFormatterFactory
......................................................................

Simplify EntityIdFormatterFactory

Change-Id: Ib31c1828b3aed9131458130f723206d09b468144
---
M lib/includes/formatters/EntityIdFormatterFactory.php
M lib/includes/formatters/EntityIdHtmlLinkFormatterFactory.php
M lib/tests/phpunit/formatters/EntityIdHtmlLinkFormatterFactoryTest.php
M repo/includes/EntityParserOutputGenerator.php
M repo/includes/View/EntityViewFactory.php
M repo/includes/WikibaseRepo.php
M repo/tests/phpunit/includes/View/EntityViewFactoryTest.php
7 files changed, 23 insertions(+), 52 deletions(-)


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

diff --git a/lib/includes/formatters/EntityIdFormatterFactory.php 
b/lib/includes/formatters/EntityIdFormatterFactory.php
index feca78c..c41bb13 100644
--- a/lib/includes/formatters/EntityIdFormatterFactory.php
+++ b/lib/includes/formatters/EntityIdFormatterFactory.php
@@ -1,7 +1,7 @@
 <?php
 namespace Wikibase\Lib;
 
-use ValueFormatters\FormatterOptions;
+use Wikibase\Lib\Store\LabelLookup;
 
 /**
  * A factory interface for generating EntityIdFormatters.
@@ -26,10 +26,10 @@
        public function getOutputFormat();
 
        /**
-        * @param FormatterOptions $options
+        * @param LabelLookup $labelLookup
         *
         * @return EntityIdFormatter
         */
-       public function getEntityIdFormater( FormatterOptions $options );
+       public function getEntityIdFormater( LabelLookup $labelLookup );
 
 }
diff --git a/lib/includes/formatters/EntityIdHtmlLinkFormatterFactory.php 
b/lib/includes/formatters/EntityIdHtmlLinkFormatterFactory.php
index fe189c1..5a1c107 100644
--- a/lib/includes/formatters/EntityIdHtmlLinkFormatterFactory.php
+++ b/lib/includes/formatters/EntityIdHtmlLinkFormatterFactory.php
@@ -3,6 +3,7 @@
 
 use ValueFormatters\FormatterOptions;
 use Wikibase\Lib\Store\EntityTitleLookup;
+use Wikibase\Lib\Store\LabelLookup;
 
 /**
  * A factory for generating EntityIdHtmlLinkFormatters.
@@ -11,11 +12,6 @@
  * @author Daniel Kinzler
  */
 class EntityIdHtmlLinkFormatterFactory implements EntityIdFormatterFactory {
-
-       /**
-        * @var FormatterLabelLookupFactory
-        */
-       private $labelLookupFactory;
 
        /**
         * @var EntityTitleLookup
@@ -28,16 +24,13 @@
        private $languageNameLookup;
 
        /**
-        * @param FormatterLabelLookupFactory $labelLookupFactory
         * @param EntityTitleLookup $titleLookup
         * @param LanguageNameLookup $languageNameLookup
         */
        public function __construct(
-               FormatterLabelLookupFactory $labelLookupFactory,
                EntityTitleLookup $titleLookup,
                LanguageNameLookup $languageNameLookup
        ) {
-               $this->labelLookupFactory = $labelLookupFactory;
                $this->titleLookup = $titleLookup;
                $this->languageNameLookup = $languageNameLookup;
        }
@@ -58,8 +51,7 @@
         *
         * @return EntityIdHtmlLinkFormatter
         */
-       public function getEntityIdFormater( FormatterOptions $options ) {
-               $labelLookup = $this->labelLookupFactory->getLabelLookup( 
$options );
+       public function getEntityIdFormater( LabelLookup $labelLookup ) {
                return new EntityIdHtmlLinkFormatter(
                        $labelLookup,
                        $this->titleLookup,
diff --git 
a/lib/tests/phpunit/formatters/EntityIdHtmlLinkFormatterFactoryTest.php 
b/lib/tests/phpunit/formatters/EntityIdHtmlLinkFormatterFactoryTest.php
index cd9d0e6..a15e948 100644
--- a/lib/tests/phpunit/formatters/EntityIdHtmlLinkFormatterFactoryTest.php
+++ b/lib/tests/phpunit/formatters/EntityIdHtmlLinkFormatterFactoryTest.php
@@ -2,7 +2,7 @@
 
 namespace Wikibase\Lib\Test;
 
-use ValueFormatters\FormatterOptions;
+use PHPUnit_Framework_TestCase;
 use Wikibase\Lib\EntityIdHtmlLinkFormatterFactory;
 use Wikibase\Lib\SnakFormatter;
 
@@ -16,23 +16,12 @@
  * @licence GNU GPL v2+
  * @author Daniel Kinzler
  */
-class EntityIdHtmlLinkFormatterFactoryTest extends \PHPUnit_Framework_TestCase 
{
+class EntityIdHtmlLinkFormatterFactoryTest extends PHPUnit_Framework_TestCase {
 
        private function getFormatterFactory() {
-               $labelLookup = $this->getMock( 'Wikibase\Lib\Store\LabelLookup' 
);
-
-               $labelLookupFactory = $this->getMockBuilder( 
'Wikibase\Lib\FormatterLabelLookupFactory' )
-                       ->disableOriginalConstructor()
-                       ->getMock();
-
-               $labelLookupFactory->expects( $this->any() )
-                       ->method( 'getLabelLookup' )
-                       ->will( $this->returnValue( $labelLookup ) );
-
                $titleLookup = $this->getMock( 
'Wikibase\Lib\Store\EntityTitleLookup' );
 
                return new EntityIdHtmlLinkFormatterFactory(
-                       $labelLookupFactory,
                        $titleLookup,
                        $this->getMock( 'Wikibase\Lib\LanguageNameLookup' )
                );
@@ -47,7 +36,7 @@
        public function testGetEntityIdFormatter() {
                $factory = $this->getFormatterFactory();
 
-               $formatter = $factory->getEntityIdFormater( new 
FormatterOptions() );
+               $formatter = $factory->getEntityIdFormater( $this->getMock( 
'Wikibase\Lib\Store\LabelLookup' ) );
                $this->assertInstanceOf( 'Wikibase\Lib\EntityIdFormatter', 
$formatter );
        }
 
diff --git a/repo/includes/EntityParserOutputGenerator.php 
b/repo/includes/EntityParserOutputGenerator.php
index 6a883da..a83129a 100644
--- a/repo/includes/EntityParserOutputGenerator.php
+++ b/repo/includes/EntityParserOutputGenerator.php
@@ -318,8 +318,8 @@
                $entityView = $this->entityViewFactory->newEntityView(
                        $entityRevision->getEntity()->getType(),
                        $this->languageCode,
-                       $this->languageFallbackChain,
                        $labelLookup,
+                       $this->languageFallbackChain,
                        $editable
                );
 
diff --git a/repo/includes/View/EntityViewFactory.php 
b/repo/includes/View/EntityViewFactory.php
index 5717126..b9a2367 100644
--- a/repo/includes/View/EntityViewFactory.php
+++ b/repo/includes/View/EntityViewFactory.php
@@ -141,8 +141,8 @@
         *
         * @param string $entityType
         * @param string $languageCode
+        * @param LabelLookup $labelLookup
         * @param LanguageFallbackChain|null $fallbackChain
-        * @param LabelLookup|null $labelLookup
         * @param bool $editable
         *
         * @throws InvalidArgumentException
@@ -151,8 +151,8 @@
        public function newEntityView(
                $entityType,
                $languageCode,
+               LabelLookup $labelLookup,
                LanguageFallbackChain $fallbackChain = null,
-               LabelLookup $labelLookup = null,
                $editable = true
         ) {
                $entityTermsView = $this->newEntityTermsView( $languageCode );
@@ -205,16 +205,16 @@
        /**
         * @param string $languageCode
         * @param LanguageFallbackChain|null $fallbackChain
-        * @param LabelLookup|null $labelLookup
+        * @param LabelLookup $labelLookup
         *
         * @return StatementGroupListView
         */
        private function newStatementGroupListView(
                $languageCode,
                LanguageFallbackChain $fallbackChain = null,
-               LabelLookup $labelLookup = null
+               LabelLookup $labelLookup
        ) {
-               $propertyIdFormatter = $this->getPropertyIdFormatter( 
$languageCode, $fallbackChain, $labelLookup );
+               $propertyIdFormatter = $this->getPropertyIdFormatter( 
$labelLookup );
 
                $snakHtmlGenerator = new SnakHtmlGenerator(
                        $this->templateFactory,
@@ -296,22 +296,12 @@
        }
 
        /**
-        * @param string $languageCode
-        * @param LanguageFallbackChain|null $languageFallbackChain
-        * @param LabelLookup|null $labelLookup
+        * @param LabelLookup $labelLookup
         *
         * @return EntityIdFormatter
         */
-       private function getPropertyIdFormatter(
-               $languageCode,
-               LanguageFallbackChain $languageFallbackChain = null,
-               LabelLookup $labelLookup = null
-       ) {
-               $formatterOptions = $this->getFormatterOptions( $languageCode, 
$languageFallbackChain, $labelLookup );
-
-               return $this->idFormatterFactory->getEntityIdFormater(
-                       $formatterOptions
-               );
+       private function getPropertyIdFormatter( LabelLookup $labelLookup ) {
+               return $this->idFormatterFactory->getEntityIdFormater( 
$labelLookup );
        }
 
 }
diff --git a/repo/includes/WikibaseRepo.php b/repo/includes/WikibaseRepo.php
index 980ce09..b83a7f8 100644
--- a/repo/includes/WikibaseRepo.php
+++ b/repo/includes/WikibaseRepo.php
@@ -1000,9 +1000,8 @@
                return $this->entityNamespaceLookup;
        }
 
-       private function getEntityIdHtmlLinkFormatter() {
+       private function getEntityIdHtmlLinkFormatterFactory() {
                return new EntityIdHtmlLinkFormatterFactory(
-                       new FormatterLabelLookupFactory( $this->getTermLookup() 
),
                        $this->getEntityTitleLookup(),
                        new LanguageNameLookup()
                );
@@ -1014,7 +1013,7 @@
        public function getEntityParserOutputGeneratorFactory() {
 
                $entityViewFactory = new EntityViewFactory(
-                       $this->getEntityIdHtmlLinkFormatter(),
+                       $this->getEntityIdHtmlLinkFormatterFactory(),
                        $this->getSnakFormatterFactory(),
                        $this->getEntityLookup(),
                        $this->getSiteStore(),
diff --git a/repo/tests/phpunit/includes/View/EntityViewFactoryTest.php 
b/repo/tests/phpunit/includes/View/EntityViewFactoryTest.php
index 757d9b0..56b1dd6 100644
--- a/repo/tests/phpunit/includes/View/EntityViewFactoryTest.php
+++ b/repo/tests/phpunit/includes/View/EntityViewFactoryTest.php
@@ -28,8 +28,8 @@
                $entityView = $entityViewFactory->newEntityView(
                        $entityType,
                        'de',
-                       $languageFallback,
-                       $this->getMock( 'Wikibase\Lib\Store\LabelLookup' )
+                       $this->getMock( 'Wikibase\Lib\Store\LabelLookup' ),
+                       $languageFallback
                );
 
                $this->assertInstanceOf( $expectedClass, $entityView );
@@ -49,7 +49,8 @@
 
                $entityViewFactory->newEntityView(
                        'kittens',
-                       'de'
+                       'de',
+                       $this->getMock( 'Wikibase\Lib\Store\LabelLookup' )
                );
        }
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib31c1828b3aed9131458130f723206d09b468144
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Adrian Lang <adrian.he...@wikimedia.de>

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

Reply via email to