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

Change subject: Small clean ups in EntityParserOutputGenerator related code
......................................................................


Small clean ups in EntityParserOutputGenerator related code

* Add missing and fix wrong PHPDoc tags.
* Optimize use clauses.
* Use switch for code that looks like a switch.
* Rename $revId to $revisionId.

Change-Id: I3bc3a356c63c33bc82cf960b27eab77e1f86a03a
---
M repo/includes/EntityParserOutputGenerator.php
M repo/includes/EntityParserOutputGeneratorFactory.php
M repo/includes/GenericEventDispatcher.php
M repo/includes/IO/LineReader.php
M repo/includes/View/EntityViewFactory.php
M repo/includes/content/EntityContent.php
M repo/includes/content/EntityHandler.php
M repo/includes/content/PropertyHandler.php
M repo/includes/store/sql/EntityPerPageTable.php
M repo/tests/phpunit/includes/EntityParserOutputGeneratorFactoryTest.php
10 files changed, 77 insertions(+), 59 deletions(-)

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



diff --git a/repo/includes/EntityParserOutputGenerator.php 
b/repo/includes/EntityParserOutputGenerator.php
index 5fc6bd5..db5e412 100644
--- a/repo/includes/EntityParserOutputGenerator.php
+++ b/repo/includes/EntityParserOutputGenerator.php
@@ -2,10 +2,11 @@
 
 namespace Wikibase;
 
-use OutOfBoundsException;
 use ParserOutput;
 use Wikibase\DataModel\Entity\Entity;
+use Wikibase\DataModel\Entity\EntityId;
 use Wikibase\DataModel\Entity\Item;
+use Wikibase\DataModel\SiteLink;
 use Wikibase\DataModel\SiteLinkList;
 use Wikibase\DataModel\Snak\Snak;
 use Wikibase\DataModel\StatementListProvider;
@@ -101,7 +102,9 @@
         *
         * @return ParserOutput
         */
-       public function getParserOutput( EntityRevision $entityRevision, 
$editable = true,
+       public function getParserOutput(
+               EntityRevision $entityRevision,
+               $editable = true,
                $generateHtml = true
        ) {
                $parserOutput = new ParserOutput();
@@ -243,6 +246,7 @@
         * @param SiteLinkList $siteLinkList
         */
        private function addBadgesToParserOutput( ParserOutput $parserOutput, 
SiteLinkList $siteLinkList ) {
+               /** @var SiteLink $siteLink */
                foreach ( $siteLinkList as $siteLink ) {
                        foreach ( $siteLink->getBadges() as $badge ) {
                                $parserOutput->addLink( 
$this->entityTitleLookup->getTitleForId( $badge ) );
@@ -276,13 +280,13 @@
         * @param ParserOutput $parserOutput
         * @param EntityRevision $entityRevision
         * @param EntityInfo $entityInfo obtained from 
EntityInfoBuilder::getEntityInfo
-        * @param boolean $editable
+        * @param bool $editable
         */
        private function addHtmlToParserOutput(
                ParserOutput $parserOutput,
                EntityRevision $entityRevision,
                EntityInfo $entityInfo,
-               $editable
+               $editable = true
        ) {
 
                $labelLookup = new LanguageFallbackLabelLookup(
@@ -303,7 +307,11 @@
                $parserOutput->setExtensionData( 'wikibase-view-chunks', 
$entityView->getPlaceholders() );
        }
 
-       private function addModules( ParserOutput $parserOutput, $editable ) {
+       /**
+        * @param ParserOutput $parserOutput
+        * @param bool $editable
+        */
+       private function addModules( ParserOutput $parserOutput, $editable = 
true ) {
                // make css available for JavaScript-less browsers
                $parserOutput->addModuleStyles( array(
                        'wikibase.common',
diff --git a/repo/includes/EntityParserOutputGeneratorFactory.php 
b/repo/includes/EntityParserOutputGeneratorFactory.php
index 8eeca89..863d974 100644
--- a/repo/includes/EntityParserOutputGeneratorFactory.php
+++ b/repo/includes/EntityParserOutputGeneratorFactory.php
@@ -107,15 +107,13 @@
        private function getLanguageCode( ParserOptions $options = null ) {
                // NOTE: Parser Options language overrides context language!
                if ( $options !== null ) {
-                       $languageCode = $options->getUserLang();
-               } else {
-                       // @todo do we still need to fallback to context here?
-                       // if needed, then maybe inject some 'default' in the 
constructor.
-                       $context = RequestContext::getMain();
-                       $languageCode = $context->getLanguage()->getCode();
+                       return $options->getUserLang();
                }
 
-               return $languageCode;
+               // @todo do we still need to fallback to context here?
+               // if needed, then maybe inject some 'default' in the 
constructor.
+               $context = RequestContext::getMain();
+               return $context->getLanguage()->getCode();
        }
 
        /**
diff --git a/repo/includes/GenericEventDispatcher.php 
b/repo/includes/GenericEventDispatcher.php
index 981a14f..a064f2f 100644
--- a/repo/includes/GenericEventDispatcher.php
+++ b/repo/includes/GenericEventDispatcher.php
@@ -2,6 +2,8 @@
 
 namespace Wikibase\Repo;
 
+use InvalidArgumentException;
+
 /**
  * Dispatches a notification to a set of watchers.
  *
@@ -40,12 +42,12 @@
         *
         * @param object $listener
         *
-        * @throws \InvalidArgumentException
+        * @throws InvalidArgumentException
         * @return mixed The listener key, for removing the listener later.
         */
        public function registerWatcher( $listener ) {
                if ( !is_subclass_of( $listener, $this->interface ) ) {
-                       throw new \InvalidArgumentException( '$listener must 
implement ' . $this->interface );
+                       throw new InvalidArgumentException( '$listener must 
implement ' . $this->interface );
                }
 
                $key = ++$this->key;
@@ -59,11 +61,11 @@
         *
         * @param mixed $key A watcher key as returned by registerWatcher().
         *
-        * @throws \InvalidArgumentException
+        * @throws InvalidArgumentException
         */
        public function unregisterWatcher( $key ) {
                if ( is_object( $key ) || is_array( $key ) ) {
-                       throw new \InvalidArgumentException( '$key must be a 
primitive value' );
+                       throw new InvalidArgumentException( '$key must be a 
primitive value' );
                }
 
                if ( isset( $this->watchers[$key] ) ) {
@@ -79,11 +81,11 @@
         *
         * @param * any extra parameters are passed to the watcher method.
         *
-        * @throws \InvalidArgumentException
+        * @throws InvalidArgumentException
         */
        public function dispatch( $event ) {
                if ( !is_string( $event ) ) {
-                       throw new \InvalidArgumentException( '$event must be a 
string' );
+                       throw new InvalidArgumentException( '$event must be a 
string' );
                }
 
                $args = func_get_args();
diff --git a/repo/includes/IO/LineReader.php b/repo/includes/IO/LineReader.php
index 6ec1519..885df72 100644
--- a/repo/includes/IO/LineReader.php
+++ b/repo/includes/IO/LineReader.php
@@ -3,6 +3,7 @@
 namespace Wikibase\Repo\IO;
 
 use Disposable;
+use InvalidArgumentException;
 use Iterator;
 
 /**
@@ -50,19 +51,19 @@
         * @param bool $autoDispose Whether to automatically call dispose() 
when reaching EOF
         *             or when this reader is destructed.
         *
-        * @throws \InvalidArgumentException
+        * @throws InvalidArgumentException
         */
        public function __construct( $fileHandle, $canClose = true, 
$autoDispose = false ) {
                if ( !is_resource( $fileHandle ) ) {
-                       throw new \InvalidArgumentException( '$fileHandle must 
be a file resource.' );
+                       throw new InvalidArgumentException( '$fileHandle must 
be a file resource.' );
                }
 
                if ( !is_bool( $canClose ) ) {
-                       throw new \InvalidArgumentException( '$canClose must be 
a boolean.' );
+                       throw new InvalidArgumentException( '$canClose must be 
a boolean.' );
                }
 
                if ( !is_bool( $autoDispose ) ) {
-                       throw new \InvalidArgumentException( '$autoDispose must 
be a boolean.' );
+                       throw new InvalidArgumentException( '$autoDispose must 
be a boolean.' );
                }
 
                $this->fileHandle = $fileHandle;
@@ -152,4 +153,5 @@
                        $this->next();
                }
        }
+
 }
diff --git a/repo/includes/View/EntityViewFactory.php 
b/repo/includes/View/EntityViewFactory.php
index 30c6ac8..6467dfb 100644
--- a/repo/includes/View/EntityViewFactory.php
+++ b/repo/includes/View/EntityViewFactory.php
@@ -96,10 +96,11 @@
                $language = Language::factory( $languageCode );
 
                // @fixme support more entity types
-               if ( $entityType === 'item' ) {
-                       return new ItemView( $fingerprintView, $claimsView, 
$language, $this->siteLinkGroups, $editable );
-               } elseif ( $entityType === 'property' ) {
-                       return new PropertyView( $fingerprintView, $claimsView, 
$language );
+               switch ( $entityType ) {
+                       case 'item':
+                               return new ItemView( $fingerprintView, 
$claimsView, $language, $this->siteLinkGroups, $editable );
+                       case 'property':
+                               return new PropertyView( $fingerprintView, 
$claimsView, $language, $editable );
                }
 
                throw new InvalidArgumentException( 'No EntityView for entity 
type: ' . $entityType );
diff --git a/repo/includes/content/EntityContent.php 
b/repo/includes/content/EntityContent.php
index af84f27..7b02872 100644
--- a/repo/includes/content/EntityContent.php
+++ b/repo/includes/content/EntityContent.php
@@ -184,9 +184,12 @@
         *
         * @return DataUpdate[]
         */
-       public function getSecondaryDataUpdates( Title $title, Content 
$oldContent = null,
-               $recursive = false, ParserOutput $parserOutput = null ) {
-
+       public function getSecondaryDataUpdates(
+               Title $title,
+               Content $oldContent = null,
+               $recursive = false,
+               ParserOutput $parserOutput = null
+       ) {
                /** @var EntityHandler $handler */
                $handler = $this->getContentHandler();
                $updates = $handler->getEntityModificationUpdates( $this, 
$title );
@@ -208,19 +211,22 @@
         * @see Content::getParserOutput
         *
         * @param Title $title
-        * @param int|null $revId
+        * @param int|null $revisionId
         * @param ParserOptions|null $options
         * @param bool $generateHtml
         *
         * @return ParserOutput
         */
-       public function getParserOutput( Title $title, $revId = null, 
ParserOptions $options = null,
+       public function getParserOutput(
+               Title $title,
+               $revisionId = null,
+               ParserOptions $options = null,
                $generateHtml = true
        ) {
                if ( $this->isRedirect() ) {
                        return $this->getParserOutputForRedirect( $generateHtml 
);
                } else {
-                       return $this->getParserOutputFromEntityView( $title, 
$revId, $options, $generateHtml );
+                       return $this->getParserOutputFromEntityView( $title, 
$revisionId, $options, $generateHtml );
                }
        }
 
@@ -260,14 +266,17 @@
         * @note Will fail if this EntityContent represents a redirect.
         *
         * @param Title $title
-        * @param null $revId
-        * @param ParserOptions $options
+        * @param int|null $revisionId
+        * @param ParserOptions|null $options
         * @param bool $generateHtml
         *
         * @return ParserOutput
         */
-       protected function getParserOutputFromEntityView( Title $title, $revId 
= null,
-               ParserOptions $options = null, $generateHtml = true
+       protected function getParserOutputFromEntityView(
+               Title $title,
+               $revisionId = null,
+               ParserOptions $options = null,
+               $generateHtml = true
        ) {
                // @todo: move this to the ContentHandler
                $entityParserOutputGeneratorFactory = 
WikibaseRepo::getDefaultInstance()->getEntityParserOutputGeneratorFactory();
@@ -276,13 +285,10 @@
                        $options
                );
 
+               $entityRevision = $this->getEntityRevision( $title, $revisionId 
);
                $editable = $options ? $options->getEditSection() : true;
 
-               $output = $outputGenerator->getParserOutput(
-                       $this->getEntityRevision( $title, $revId ),
-                       $editable,
-                       $generateHtml
-               );
+               $output = $outputGenerator->getParserOutput( $entityRevision, 
$editable, $generateHtml );
 
                // Since the output depends on the user language, we must make 
sure
                // ParserCache::getKey() includes it in the cache key.
@@ -296,16 +302,16 @@
 
        /**
         * @param Title $title
-        * @param int|null $revId
+        * @param int|null $revisionId
         *
         * @return EntityRevision
         */
-       private function getEntityRevision( Title $title, $revId = null ) {
-               if ( $revId === null || $revId === 0 ) {
-                       $revId = $title->getLatestRevID();
+       private function getEntityRevision( Title $title, $revisionId = null ) {
+               if ( $revisionId === null || $revisionId === 0 ) {
+                       $revisionId = $title->getLatestRevID();
                }
 
-               return new EntityRevision( $this->getEntity(), $revId );
+               return new EntityRevision( $this->getEntity(), $revisionId );
        }
 
        /**
diff --git a/repo/includes/content/EntityHandler.php 
b/repo/includes/content/EntityHandler.php
index 7a7f942..69fb268 100644
--- a/repo/includes/content/EntityHandler.php
+++ b/repo/includes/content/EntityHandler.php
@@ -34,7 +34,7 @@
 use Wikibase\Validators\ValidatorErrorLocalizer;
 
 /**
- * Base handler class for Wikibase\DataModel\Entity\Entity content classes.
+ * Base handler class for Entity content classes.
  *
  * @licence GNU GPL v2+
  * @author Daniel Kinzler
@@ -87,7 +87,7 @@
         *        the blob an the serialization format. It must return true if 
re-serialization is needed.
         *        False positives are acceptable, false negatives are not.
         *
-        * @throws \InvalidArgumentException
+        * @throws InvalidArgumentException
         */
        public function __construct(
                $modelId,
@@ -141,7 +141,7 @@
         * @return string
         */
        protected function getDiffEngineClass() {
-               return '\Wikibase\Repo\Diff\EntityContentDiffView';
+               return 'Wikibase\Repo\Diff\EntityContentDiffView';
        }
 
        /**
diff --git a/repo/includes/content/PropertyHandler.php 
b/repo/includes/content/PropertyHandler.php
index 87543e5..bcf730e 100644
--- a/repo/includes/content/PropertyHandler.php
+++ b/repo/includes/content/PropertyHandler.php
@@ -44,7 +44,7 @@
         * @return string
         */
        protected function getContentClass() {
-               return '\Wikibase\PropertyContent';
+               return 'Wikibase\PropertyContent';
        }
 
        /**
@@ -93,7 +93,7 @@
         */
        protected function newContent( Entity $property ) {
                if ( ! $property instanceof Property ) {
-                       throw new \InvalidArgumentException( '$property must be 
an instance of Property' );
+                       throw new InvalidArgumentException( '$property must be 
an instance of Property' );
                }
 
                return PropertyContent::newFromProperty( $property );
@@ -104,10 +104,10 @@
         */
        public function getActionOverrides() {
                return array(
-                       'history' => '\Wikibase\HistoryPropertyAction',
-                       'view' => '\Wikibase\ViewPropertyAction',
-                       'edit' => '\Wikibase\EditPropertyAction',
-                       'submit' => '\Wikibase\SubmitPropertyAction',
+                       'history' => 'Wikibase\HistoryPropertyAction',
+                       'view' => 'Wikibase\ViewPropertyAction',
+                       'edit' => 'Wikibase\EditPropertyAction',
+                       'submit' => 'Wikibase\SubmitPropertyAction',
                );
        }
 
diff --git a/repo/includes/store/sql/EntityPerPageTable.php 
b/repo/includes/store/sql/EntityPerPageTable.php
index fd7b91d..d2df3a1 100644
--- a/repo/includes/store/sql/EntityPerPageTable.php
+++ b/repo/includes/store/sql/EntityPerPageTable.php
@@ -78,7 +78,7 @@
         * @param int $pageId
         * @param EntityId $targetId
         *
-        * @throws \InvalidArgumentException
+        * @throws InvalidArgumentException
         */
        private function addRow( EntityId $entityId, $pageId, EntityId 
$targetId = null ) {
                if ( !is_int( $pageId ) ) {
diff --git 
a/repo/tests/phpunit/includes/EntityParserOutputGeneratorFactoryTest.php 
b/repo/tests/phpunit/includes/EntityParserOutputGeneratorFactoryTest.php
index c1c2ace..599f9d5 100644
--- a/repo/tests/phpunit/includes/EntityParserOutputGeneratorFactoryTest.php
+++ b/repo/tests/phpunit/includes/EntityParserOutputGeneratorFactoryTest.php
@@ -4,10 +4,11 @@
 
 use Language;
 use ParserOptions;
-use TestUser;
 use Wikibase\Repo\WikibaseRepo;
 
 /**
+ * @covers Wikibase\EntityParserOutputGeneratorFactory
+ *
  * @group Database
  *
  * @licence GNU GPL v2+
@@ -18,7 +19,7 @@
        public function testGetEntityParserOutputGenerator() {
                $parserOutputGeneratorFactory = 
$this->getEntityParserOutputGeneratorFactory();
 
-               $testUser = new TestUser( 'Wikibase User' );
+               $testUser = new \TestUser( 'Wikibase User' );
 
                $parserOutputGenerator = 
$parserOutputGeneratorFactory->getEntityParserOutputGenerator(
                        new ParserOptions( $testUser->getUser(), 
Language::factory( 'en' ) )
@@ -30,7 +31,7 @@
        public function 
testGetEntityParserOutputGenerator_noParserOptionLanguage() {
                $parserOutputGeneratorFactory = 
$this->getEntityParserOutputGeneratorFactory();
 
-               $testUser = new TestUser( 'Wikibase User' );
+               $testUser = new \TestUser( 'Wikibase User' );
 
                $parserOutputGenerator = 
$parserOutputGeneratorFactory->getEntityParserOutputGenerator(
                        new ParserOptions( $testUser->getUser() )

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I3bc3a356c63c33bc82cf960b27eab77e1f86a03a
Gerrit-PatchSet: 8
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de>
Gerrit-Reviewer: Addshore <addshorew...@gmail.com>
Gerrit-Reviewer: Adrian Lang <adrian.l...@wikimedia.de>
Gerrit-Reviewer: Aude <aude.w...@gmail.com>
Gerrit-Reviewer: Daniel Kinzler <daniel.kinz...@wikimedia.de>
Gerrit-Reviewer: Hoo man <h...@online.de>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to