jenkins-bot has submitted this change and it was merged.

Change subject: Inject StatementGrouper into StatementSectionsView instead
......................................................................


Inject StatementGrouper into StatementSectionsView instead

Suggested in
https://gerrit.wikimedia.org/r/#/c/256709/1/view/src/ItemView.php
I also think this is a good idea It reduces the total number of
injections.

Bug: T119596
Change-Id: Ic458864c9d7fd382c4e538613f591fb60539ac8b
---
M view/src/EntityViewFactory.php
M view/src/ItemView.php
M view/src/PropertyView.php
M view/src/StatementSectionsView.php
M view/tests/phpunit/ItemViewTest.php
M view/tests/phpunit/PropertyViewTest.php
M view/tests/phpunit/StatementSectionsViewTest.php
7 files changed, 51 insertions(+), 50 deletions(-)

Approvals:
  Hoo man: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/view/src/EntityViewFactory.php b/view/src/EntityViewFactory.php
index 12c9d99..dfac187 100644
--- a/view/src/EntityViewFactory.php
+++ b/view/src/EntityViewFactory.php
@@ -166,6 +166,7 @@
                $entityTermsView = $this->newEntityTermsView( $languageCode, 
$editSectionGenerator );
 
                $statementSectionsView = $this->newStatementSectionsView(
+                       $entityType,
                        $languageCode,
                        $fallbackChain,
                        $labelDescriptionLookup,
@@ -191,7 +192,6 @@
                                return new ItemView(
                                        $this->templateFactory,
                                        $entityTermsView,
-                                       $this->statementGrouper,
                                        $statementSectionsView,
                                        $language,
                                        $siteLinksView,
@@ -201,7 +201,6 @@
                                return new PropertyView(
                                        $this->templateFactory,
                                        $entityTermsView,
-                                       $this->statementGrouper,
                                        $statementSectionsView,
                                        $this->dataTypeFactory,
                                        $language
@@ -212,6 +211,7 @@
        }
 
        /**
+        * @param string $entityType
         * @param string $languageCode
         * @param LanguageFallbackChain $fallbackChain
         * @param LabelDescriptionLookup $labelDescriptionLookup
@@ -220,32 +220,37 @@
         * @return StatementSectionsView
         */
        private function newStatementSectionsView(
+               $entityType,
                $languageCode,
                LanguageFallbackChain $fallbackChain,
                LabelDescriptionLookup $labelDescriptionLookup,
                EditSectionGenerator $editSectionGenerator
        ) {
-               $propertyIdFormatter = 
$this->htmlIdFormatterFactory->getEntityIdFormatter( $labelDescriptionLookup );
-
+               $snakFormatter = 
$this->htmlSnakFormatterFactory->getSnakFormatter(
+                       $languageCode,
+                       $fallbackChain,
+                       $labelDescriptionLookup
+               );
+               $propertyIdFormatter = 
$this->htmlIdFormatterFactory->getEntityIdFormatter(
+                       $labelDescriptionLookup
+               );
                $snakHtmlGenerator = new SnakHtmlGenerator(
                        $this->templateFactory,
-                       $this->htmlSnakFormatterFactory->getSnakFormatter( 
$languageCode, $fallbackChain, $labelDescriptionLookup ),
+                       $snakFormatter,
                        $propertyIdFormatter
                );
-
-               $claimHtmlGenerator = new ClaimHtmlGenerator(
-                       $this->templateFactory,
-                       $snakHtmlGenerator
-               );
-
                $statementGroupListView = new StatementGroupListView(
                        $this->templateFactory,
                        $propertyIdFormatter,
                        $editSectionGenerator,
-                       $claimHtmlGenerator
+                       new ClaimHtmlGenerator( $this->templateFactory, 
$snakHtmlGenerator )
                );
 
-               return new StatementSectionsView( $this->templateFactory, 
$statementGroupListView );
+               return new StatementSectionsView(
+                       $this->templateFactory,
+                       $this->statementGrouper,
+                       $statementGroupListView
+               );
        }
 
        /**
diff --git a/view/src/ItemView.php b/view/src/ItemView.php
index 28d38a3..4af2034 100644
--- a/view/src/ItemView.php
+++ b/view/src/ItemView.php
@@ -5,7 +5,6 @@
 use InvalidArgumentException;
 use Language;
 use Wikibase\DataModel\Entity\Item;
-use Wikibase\DataModel\Services\Statement\Grouper\StatementGrouper;
 use Wikibase\EntityRevision;
 use Wikibase\View\Template\TemplateFactory;
 
@@ -20,11 +19,6 @@
  * @author Daniel Werner
  */
 class ItemView extends EntityView {
-
-       /**
-        * @var StatementGrouper
-        */
-       private $statementGrouper;
 
        /**
         * @var StatementSectionsView
@@ -46,7 +40,6 @@
         *
         * @param TemplateFactory $templateFactory
         * @param EntityTermsView $entityTermsView
-        * @param StatementGrouper $statementGrouper
         * @param StatementSectionsView $statementSectionsView
         * @param Language $language
         * @param SiteLinksView $siteLinksView
@@ -55,7 +48,6 @@
        public function __construct(
                TemplateFactory $templateFactory,
                EntityTermsView $entityTermsView,
-               StatementGrouper $statementGrouper,
                StatementSectionsView $statementSectionsView,
                Language $language,
                SiteLinksView $siteLinksView,
@@ -63,7 +55,6 @@
        ) {
                parent::__construct( $templateFactory, $entityTermsView, 
$language );
 
-               $this->statementGrouper = $statementGrouper;
                $this->statementSectionsView = $statementSectionsView;
                $this->siteLinksView = $siteLinksView;
                $this->siteLinkGroups = $siteLinkGroups;
@@ -80,8 +71,7 @@
                }
 
                $html = parent::getMainHtml( $entityRevision );
-               $statementLists = $this->statementGrouper->groupStatements( 
$item->getStatements() );
-               $html .= $this->statementSectionsView->getHtml( $statementLists 
);
+               $html .= $this->statementSectionsView->getHtml( 
$item->getStatements() );
 
                return $html;
        }
diff --git a/view/src/PropertyView.php b/view/src/PropertyView.php
index 59456f5..c2276d9 100644
--- a/view/src/PropertyView.php
+++ b/view/src/PropertyView.php
@@ -7,7 +7,6 @@
 use InvalidArgumentException;
 use Language;
 use Wikibase\DataModel\Entity\Property;
-use Wikibase\DataModel\Services\Statement\Grouper\StatementGrouper;
 use Wikibase\EntityRevision;
 use Wikibase\View\Template\TemplateFactory;
 
@@ -24,11 +23,6 @@
 class PropertyView extends EntityView {
 
        /**
-        * @var StatementGrouper
-        */
-       private $statementGrouper;
-
-       /**
         * @var StatementSectionsView
         */
        private $statementSectionsView;
@@ -41,7 +35,6 @@
        /**
         * @param TemplateFactory $templateFactory
         * @param EntityTermsView $entityTermsView
-        * @param StatementGrouper $statementGrouper
         * @param StatementSectionsView $statementSectionsView
         * @param DataTypeFactory $dataTypeFactory
         * @param Language $language
@@ -49,14 +42,12 @@
        public function __construct(
                TemplateFactory $templateFactory,
                EntityTermsView $entityTermsView,
-               StatementGrouper $statementGrouper,
                StatementSectionsView $statementSectionsView,
                DataTypeFactory $dataTypeFactory,
                Language $language
        ) {
                parent::__construct( $templateFactory, $entityTermsView, 
$language );
 
-               $this->statementGrouper = $statementGrouper;
                $this->statementSectionsView = $statementSectionsView;
                $this->dataTypeFactory = $dataTypeFactory;
        }
@@ -74,8 +65,7 @@
                $html = parent::getMainHtml( $entityRevision );
                $html .= $this->getHtmlForDataType( $this->getDataType( 
$property ) );
 
-               $statementLists = $this->statementGrouper->groupStatements( 
$property->getStatements() );
-               $html .= $this->statementSectionsView->getHtml( $statementLists 
);
+               $html .= $this->statementSectionsView->getHtml( 
$property->getStatements() );
 
                $footer = wfMessage( 'wikibase-property-footer' );
 
diff --git a/view/src/StatementSectionsView.php 
b/view/src/StatementSectionsView.php
index 59765ad..2cea236 100644
--- a/view/src/StatementSectionsView.php
+++ b/view/src/StatementSectionsView.php
@@ -3,6 +3,7 @@
 namespace Wikibase\View;
 
 use InvalidArgumentException;
+use Wikibase\DataModel\Services\Statement\Grouper\StatementGrouper;
 use Wikibase\DataModel\Statement\StatementList;
 use Wikibase\View\Template\TemplateFactory;
 
@@ -20,25 +21,33 @@
        private $templateFactory;
 
        /**
+        * @var StatementGrouper
+        */
+       private $statementGrouper;
+
+       /**
         * @var StatementGroupListView
         */
        private $statementListView;
 
        public function __construct(
                TemplateFactory $templateFactory,
+               StatementGrouper $statementGrouper,
                StatementGroupListView $statementListView
        ) {
                $this->templateFactory = $templateFactory;
+               $this->statementGrouper = $statementGrouper;
                $this->statementListView = $statementListView;
        }
 
        /**
-        * @param StatementList[] $statementLists
+        * @param StatementList $statementList
         *
         * @throws InvalidArgumentException
         * @return string HTML
         */
-       public function getHtml( array $statementLists ) {
+       public function getHtml( StatementList $statementList ) {
+               $statementLists = $this->statementGrouper->groupStatements( 
$statementList );
                $html = '';
 
                foreach ( $statementLists as $key => $statements ) {
diff --git a/view/tests/phpunit/ItemViewTest.php 
b/view/tests/phpunit/ItemViewTest.php
index de03d4e..8dca462 100644
--- a/view/tests/phpunit/ItemViewTest.php
+++ b/view/tests/phpunit/ItemViewTest.php
@@ -56,7 +56,6 @@
                        $this->getMockBuilder( 'Wikibase\View\EntityTermsView' )
                                ->disableOriginalConstructor()
                                ->getMock(),
-                       new NullStatementGrouper(),
                        $this->getMockBuilder( 
'Wikibase\View\StatementSectionsView' )
                                ->disableOriginalConstructor()
                                ->getMock(),
diff --git a/view/tests/phpunit/PropertyViewTest.php 
b/view/tests/phpunit/PropertyViewTest.php
index 7156f33..0437ab0 100644
--- a/view/tests/phpunit/PropertyViewTest.php
+++ b/view/tests/phpunit/PropertyViewTest.php
@@ -79,14 +79,11 @@
                        $this->getMockBuilder( 'Wikibase\View\EntityTermsView' )
                                ->disableOriginalConstructor()
                                ->getMock(),
-                       new NullStatementGrouper(),
                        $this->getMockBuilder( 
'Wikibase\View\StatementSectionsView' )
                                ->disableOriginalConstructor()
                                ->getMock(),
                        $this->getDataTypeFactory(),
-                       Language::factory( 'en' ),
-                       true,
-                       false
+                       Language::factory( 'en' )
                );
 
                return array(
diff --git a/view/tests/phpunit/StatementSectionsViewTest.php 
b/view/tests/phpunit/StatementSectionsViewTest.php
index 5cda73b..413b557 100644
--- a/view/tests/phpunit/StatementSectionsViewTest.php
+++ b/view/tests/phpunit/StatementSectionsViewTest.php
@@ -33,10 +33,17 @@
                ) );
        }
 
-       private function newInstance() {
+       private function newInstance( array $statementLists = array() ) {
                $templateFactory = new TemplateFactory( new TemplateRegistry( 
array(
                        'wb-section-heading' => '<HEADING id="$2" 
class="$3">$1</HEADING>',
                ) ) );
+
+               $statementGrouper = $this->getMock(
+                       
'Wikibase\DataModel\Services\Statement\Grouper\StatementGrouper'
+               );
+               $statementGrouper->expects( $this->any() )
+                       ->method( 'groupStatements' )
+                       ->will( $this->returnValue( $statementLists ) );
 
                $statementListView = $this->getMockBuilder( 
'Wikibase\View\StatementGroupListView' )
                        ->disableOriginalConstructor()
@@ -45,15 +52,19 @@
                        ->method( 'getHtml' )
                        ->will( $this->returnValue( '<LIST>' ) );
 
-               return new StatementSectionsView( $templateFactory, 
$statementListView );
+               return new StatementSectionsView(
+                       $templateFactory,
+                       $statementGrouper,
+                       $statementListView
+               );
        }
 
        /**
         * @dataProvider statementListsProvider
         */
        public function testGetHtml( array $statementLists, $expected ) {
-               $view = $this->newInstance();
-               $html = $view->getHtml( $statementLists );
+               $view = $this->newInstance( $statementLists );
+               $html = $view->getHtml( new StatementList() );
                $this->assertSame( $expected, $html );
        }
 
@@ -89,15 +100,15 @@
        }
 
        /**
-        * @dataProvider invalidConstructorArgumentProvider
+        * @dataProvider invalidArrayProvider
         */
        public function testGivenInvalidArray_getHtmlFails( $array ) {
-               $view = $this->newInstance();
+               $view = $this->newInstance( $array );
                $this->setExpectedException( 'InvalidArgumentException' );
-               $view->getHtml( $array );
+               $view->getHtml( new StatementList() );
        }
 
-       public function invalidConstructorArgumentProvider() {
+       public function invalidArrayProvider() {
                return array(
                        array( array( 'statements' => array() ) ),
                        array( array( array() ) ),

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ic458864c9d7fd382c4e538613f591fb60539ac8b
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <[email protected]>
Gerrit-Reviewer: Adrian Lang <[email protected]>
Gerrit-Reviewer: Daniel Kinzler <[email protected]>
Gerrit-Reviewer: Hoo man <[email protected]>
Gerrit-Reviewer: Jonas Kress (WMDE) <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to