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

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

Change subject: Unify top factory getter implementations
......................................................................

Unify top factory getter implementations

The fact that the variables can be null should be documented in my
opinion.

The fact that they are null by default should be written down
explicitely, in my opinion.

The check should be done with "=== null", in my opinion, not with
"!" (it's not a bool) and not with "isset".

Change-Id: Ib5bb23de7b32b03706ea8126434b05b35efdf9da
---
M client/includes/WikibaseClient.php
M repo/includes/WikibaseRepo.php
2 files changed, 77 insertions(+), 72 deletions(-)


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

diff --git a/client/includes/WikibaseClient.php 
b/client/includes/WikibaseClient.php
index 5161ee8..fcd51e0 100644
--- a/client/includes/WikibaseClient.php
+++ b/client/includes/WikibaseClient.php
@@ -65,11 +65,6 @@
 final class WikibaseClient {
 
        /**
-        * @var PropertyDataTypeLookup
-        */
-       public $propertyDataTypeLookup;
-
-       /**
         * @var SettingsArray
         */
        private $settings;
@@ -80,62 +75,67 @@
        private $contentLanguage;
 
        /**
-        * @var DataTypeFactory
+        * @var SiteStore|null
+        */
+       private $siteStore = null;
+
+       /**
+        * @var DataTypeFactory|null
         */
        private $dataTypeFactory = null;
 
        /**
-        * @var EntityIdParser
+        * @var EntityIdParser|null
         */
        private $entityIdParser = null;
 
        /**
-        * @var LanguageFallbackChainFactory
+        * @var PropertyDataTypeLookup|null
+        */
+       public $propertyDataTypeLookup = null;
+
+       /**
+        * @var LanguageFallbackChainFactory|null
         */
        private $languageFallbackChainFactory = null;
 
        /**
-        * @var ClientStore
+        * @var ClientStore|null
         */
        private $store = null;
 
        /**
-        * @var StringNormalizer
+        * @var StringNormalizer|null
         */
-       private $stringNormalizer;
+       private $stringNormalizer = null;
 
        /**
-        * @var Site
+        * @var Site|null
         */
        private $site = null;
 
        /**
-        * @var string
+        * @var string|null
         */
        private $siteGroup = null;
 
        /**
-        * @var OutputFormatSnakFormatterFactory
+        * @var OutputFormatSnakFormatterFactory|null
         */
-       private $snakFormatterFactory;
+       private $snakFormatterFactory = null;
 
        /**
-        * @var OutputFormatValueFormatterFactory
+        * @var OutputFormatValueFormatterFactory|null
         */
-       private $valueFormatterFactory;
+       private $valueFormatterFactory = null;
 
        /**
-        * @var SiteStore
-        */
-       private $siteStore;
-
-       /**
-        * @var LangLinkHandler
+        * @var LangLinkHandler|null
         */
        private $langLinkHandler = null;
 
        /**
-        * @var NamespaceChecker
+        * @var NamespaceChecker|null
         */
        private $namespaceChecker = null;
 
@@ -144,7 +144,7 @@
         *
         * @param SettingsArray $settings
         * @param Language $contentLanguage
-        * @param SiteStore $siteStore
+        * @param SiteStore|null $siteStore
         */
        public function __construct(
                SettingsArray $settings,
@@ -268,12 +268,11 @@
         * @return ClientStore
         */
        public function getStore() {
-               // NOTE: $repoDatabase is null per default, meaning no direct 
access to the repo's database.
-               // If $repoDatabase is false, the local wiki IS the repository.
-               // Otherwise, $repoDatabase needs to be a logical database name 
that LBFactory understands.
-               $repoDatabase = $this->settings->getSetting( 'repoDatabase' );
-
                if ( $this->store === null ) {
+                       // NOTE: $repoDatabase is null per default, meaning no 
direct access to the repo's
+                       // database. If $repoDatabase is false, the local wiki 
IS the repository. Otherwise,
+                       // $repoDatabase needs to be a logical database name 
that LBFactory understands.
+                       $repoDatabase = $this->settings->getSetting( 
'repoDatabase' );
                        $this->store = new DirectSqlStore(
                                $this->getEntityContentDataCodec(),
                                $this->getContentLanguage(),
@@ -439,7 +438,7 @@
         * @return string
         */
        public function getSiteGroup() {
-               if ( !$this->siteGroup ) {
+               if ( $this->siteGroup === null ) {
                        $this->siteGroup = $this->newSiteGroup();
                }
 
@@ -453,7 +452,7 @@
         * @return OutputFormatSnakFormatterFactory
         */
        public function getSnakFormatterFactory() {
-               if ( !$this->snakFormatterFactory ) {
+               if ( $this->snakFormatterFactory === null ) {
                        $this->snakFormatterFactory = 
$this->newSnakFormatterFactory();
                }
 
@@ -487,7 +486,7 @@
         * @return OutputFormatValueFormatterFactory
         */
        public function getValueFormatterFactory() {
-               if ( !$this->valueFormatterFactory ) {
+               if ( $this->valueFormatterFactory === null ) {
                        $this->valueFormatterFactory = 
$this->newValueFormatterFactory();
                }
 
@@ -512,7 +511,7 @@
         * @return NamespaceChecker
         */
        public function getNamespaceChecker() {
-               if ( !$this->namespaceChecker ) {
+               if ( $this->namespaceChecker === null ) {
                        $settings = $this->getSettings();
 
                        $this->namespaceChecker = new NamespaceChecker(
@@ -528,7 +527,7 @@
         * @return LangLinkHandler
         */
        public function getLangLinkHandler() {
-               if ( !$this->langLinkHandler ) {
+               if ( $this->langLinkHandler === null ) {
                        $settings = $this->getSettings();
 
                        $this->langLinkHandler = new LangLinkHandler(
@@ -567,7 +566,7 @@
         * @return SiteStore
         */
        public function getSiteStore() {
-               if ( !$this->siteStore ) {
+               if ( $this->siteStore === null ) {
                        $this->siteStore = SiteSQLStore::newInstance();
                }
 
@@ -682,7 +681,7 @@
        }
 
        /**
-        * @return RendererFactory
+        * @return PropertyClaimsRendererFactory
         */
        private function getPropertyClaimsRendererFactory() {
                $snaksFinder = new SnaksFinder(
diff --git a/repo/includes/WikibaseRepo.php b/repo/includes/WikibaseRepo.php
index bb38cf9..e5ba600 100644
--- a/repo/includes/WikibaseRepo.php
+++ b/repo/includes/WikibaseRepo.php
@@ -22,6 +22,7 @@
 use Wikibase\DataModel\Entity\EntityIdParser;
 use Wikibase\DataModel\Entity\Item;
 use Wikibase\DataModel\Entity\Property;
+use Wikibase\DataModel\Entity\PropertyDataTypeLookup;
 use Wikibase\EntityFactory;
 use Wikibase\InternalSerialization\DeserializerFactory;
 use Wikibase\InternalSerialization\SerializerFactory;
@@ -40,7 +41,6 @@
 use Wikibase\Lib\Localizer\ParseExceptionLocalizer;
 use Wikibase\Lib\OutputFormatSnakFormatterFactory;
 use Wikibase\Lib\OutputFormatValueFormatterFactory;
-use Wikibase\DataModel\Entity\PropertyDataTypeLookup;
 use Wikibase\Lib\PropertyInfoDataTypeLookup;
 use Wikibase\Lib\SnakConstructionService;
 use Wikibase\Lib\SnakFormatter;
@@ -102,64 +102,69 @@
        private $snakConstructionService = null;
 
        /**
-        * @var PropertyDataTypeLookup
+        * @var PropertyDataTypeLookup|null
         */
-       private $propertyDataTypeLookup;
+       private $propertyDataTypeLookup = null;
 
        /**
-        * @var LanguageFallbackChainFactory
+        * @var LanguageFallbackChainFactory|null
         */
-       private $languageFallbackChainFactory;
+       private $languageFallbackChainFactory = null;
 
        /**
-        * @var ClaimGuidValidator
+        * @var ClaimGuidValidator|null
         */
        private $claimGuidValidator = null;
 
        /**
-        * @var EntityIdParser
+        * @var EntityIdParser|null
         */
        private $entityIdParser = null;
 
        /**
-        * @var StringNormalizer
+        * @var StringNormalizer|null
         */
-       private $stringNormalizer;
+       private $stringNormalizer = null;
 
        /**
-        * @var OutputFormatSnakFormatterFactory
+        * @var OutputFormatSnakFormatterFactory|null
         */
-       private $snakFormatterFactory;
+       private $snakFormatterFactory = null;
 
        /**
-        * @var OutputFormatValueFormatterFactory
+        * @var OutputFormatValueFormatterFactory|null
         */
-       private $valueFormatterFactory;
+       private $valueFormatterFactory = null;
 
        /**
-        * @var SummaryFormatter
+        * @var SummaryFormatter|null
         */
-       private $summaryFormatter;
+       private $summaryFormatter = null;
 
        /**
-        * @var ExceptionLocalizer
+        * @var ExceptionLocalizer|null
         */
-       private $exceptionLocalizer;
+       private $exceptionLocalizer = null;
 
        /**
-        * @var SiteStore
+        * @var SiteStore|null
         */
-       private $siteStore;
+       private $siteStore = null;
 
        /**
-        * @var Store
+        * @var Store|null
         */
-       private $store;
+       private $store = null;
 
        /**
-        * @var TemplateRegistry
+        * @var EntityNamespaceLookup|null
         */
-       private $templateRegistry;
+       private $entityNamespaceLookup = null;
+
+       /**
+        * @var TemplateRegistry|null
+        */
+       private $templateRegistry = null;
 
        /**
         * Returns the default instance constructed using newInstance().
@@ -195,7 +200,6 @@
         */
        public function getDataTypeFactory() {
                if ( $this->dataTypeFactory === null ) {
-
                        $urlSchemes = $this->getSettings()->getSetting( 
'urlSchemes' );
                        $builders = new WikibaseDataTypeBuilders(
                                $this->getEntityLookup(),
@@ -455,7 +459,7 @@
         * @return Store
         */
        public function getStore() {
-               if ( !$this->store ) {
+               if ( $this->store === null ) {
                        $this->store = new SqlStore(
                                $this->getEntityContentDataCodec(),
                                $this->getEntityIdParser()
@@ -472,7 +476,7 @@
         * @return OutputFormatSnakFormatterFactory
         */
        public function getSnakFormatterFactory() {
-               if ( !$this->snakFormatterFactory ) {
+               if ( $this->snakFormatterFactory === null ) {
                        $this->snakFormatterFactory = 
$this->newSnakFormatterFactory();
                }
 
@@ -514,7 +518,7 @@
         * @return OutputFormatValueFormatterFactory
         */
        public function getValueFormatterFactory() {
-               if ( !$this->valueFormatterFactory ) {
+               if ( $this->valueFormatterFactory === null ) {
                        $this->valueFormatterFactory = 
$this->newValueFormatterFactory();
                }
 
@@ -536,7 +540,7 @@
         * @return ExceptionLocalizer
         */
        public function getExceptionLocalizer() {
-               if ( !$this->exceptionLocalizer ) {
+               if ( $this->exceptionLocalizer === null ) {
                        $formatter = $this->getMessageParameterFormatter();
                        $localizers = $this->getExceptionLocalizers( $formatter 
);
 
@@ -566,7 +570,7 @@
         * @return SummaryFormatter
         */
        public function getSummaryFormatter() {
-               if ( !$this->summaryFormatter ) {
+               if ( $this->summaryFormatter === null ) {
                        $this->summaryFormatter = $this->newSummaryFormatter();
                }
 
@@ -686,7 +690,7 @@
         * @return SiteStore
         */
        public function getSiteStore() {
-               if ( !$this->siteStore ) {
+               if ( $this->siteStore === null ) {
                        $this->siteStore = SiteSQLStore::newInstance();
                }
 
@@ -941,20 +945,22 @@
         * @return EntityNamespaceLookup
         */
        public function getEntityNamespaceLookup() {
-               if ( !isset( $this->entityNamespaceLookup ) ) {
+               if ( $this->entityNamespaceLookup === null ) {
                        $this->entityNamespaceLookup = new 
EntityNamespaceLookup(
-                       $this->getSettings()->getSetting( 'entityNamespaces' )
-               );
+                               $this->getSettings()->getSetting( 
'entityNamespaces' )
+                       );
                }
 
                return $this->entityNamespaceLookup;
        }
 
        public function getTemplateRegistry() {
-               if( !isset( $this->templateRegistry ) ) {
+               if ( $this->templateRegistry === null ) {
                        $this->templateRegistry = new TemplateRegistry();
-                       $this->templateRegistry->addTemplates( include( __DIR__ 
. "/../resources/templates.php" ) );
+                       $this->templateRegistry->addTemplates( include( __DIR__ 
. '/../resources/templates.php' ) );
                }
+
                return $this->templateRegistry;
        }
+
 }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib5bb23de7b32b03706ea8126434b05b35efdf9da
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