From 6805f39a305c32ffdee0980758c231ed6e244406 Mon Sep 17 00:00:00 2001 From: Thiemo Kreuz Date: Wed, 12 May 2021 10:47:18 +0200 Subject: [PATCH] Remove unused default values from class properties In all these cases the property is unconditionally set in the constructor. The extra initialisation is effectively dead code and an extra source of errors and confusion. Change-Id: Icae13390d5ca5c14e2754f3be4eb956dd7f54ac4 --- includes/EditPage.php | 2 +- includes/PageProps.php | 2 +- includes/Rest/HttpException.php | 2 +- includes/Rest/StringStream.php | 5 ++++- includes/Storage/NameTableStore.php | 6 +++--- includes/api/ApiContinuationManager.php | 2 +- includes/api/ApiOpenSearchFormatJson.php | 2 +- includes/api/ApiPageSet.php | 4 ++-- includes/cache/localisation/LocalisationCache.php | 2 +- includes/config/ServiceOptions.php | 2 +- includes/content/ContentHandlerFactory.php | 2 +- includes/deferred/HtmlFileCacheUpdate.php | 2 +- includes/filerepo/file/ForeignAPIFile.php | 2 +- includes/filerepo/file/LocalFileRestoreBatch.php | 2 +- includes/libs/ReplacementArray.php | 2 +- includes/libs/rdbms/lbfactory/LBFactorySimple.php | 2 +- includes/media/SVGReader.php | 4 ++-- includes/registration/VersionChecker.php | 6 +++--- includes/session/SessionBackend.php | 2 +- includes/session/Token.php | 6 +++--- includes/skins/SkinFactory.php | 2 +- includes/specials/SpecialBotPasswords.php | 2 +- includes/specials/helpers/ImportReporter.php | 6 +++--- includes/specials/pagers/ContribsPager.php | 2 +- includes/title/MalformedTitleException.php | 10 +++++++--- includes/user/BotPassword.php | 4 ++-- includes/user/ExternalUserNames.php | 4 ++-- tests/phpunit/mocks/TestLogger.php | 4 ++-- tests/phpunit/suites/ParserIntegrationTest.php | 2 +- 29 files changed, 51 insertions(+), 44 deletions(-) diff --git a/includes/EditPage.php b/includes/EditPage.php index e4a7ddb967b..d20a1e9c17c 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -244,7 +244,7 @@ class EditPage implements IEditObject { private $watchthis = false; /** @var bool Corresponds to $wgWatchlistExpiry */ - private $watchlistExpiryEnabled = false; + private $watchlistExpiryEnabled; /** @var WatchedItemStoreInterface */ private $watchedItemStore; diff --git a/includes/PageProps.php b/includes/PageProps.php index 4cfd0f15141..a1cc4644922 100644 --- a/includes/PageProps.php +++ b/includes/PageProps.php @@ -43,7 +43,7 @@ class PageProps { private const CACHE_SIZE = 100; // integer; max cached pages /** @var MapCacheLRU */ - private $cache = null; + private $cache; /** * @return PageProps diff --git a/includes/Rest/HttpException.php b/includes/Rest/HttpException.php index ddeca319582..154321bde43 100644 --- a/includes/Rest/HttpException.php +++ b/includes/Rest/HttpException.php @@ -12,7 +12,7 @@ namespace MediaWiki\Rest; class HttpException extends \Exception { /** @var array|null */ - private $errorData = null; + private $errorData; /** * @stable to call diff --git a/includes/Rest/StringStream.php b/includes/Rest/StringStream.php index 3ad0d960815..bd7295c28b5 100644 --- a/includes/Rest/StringStream.php +++ b/includes/Rest/StringStream.php @@ -14,7 +14,10 @@ namespace MediaWiki\Rest; * fill with null bytes as in a real file, it throws an exception instead. */ class StringStream implements CopyableStreamInterface { - private $contents = ''; + + /** @var string */ + private $contents; + /** @var int */ private $offset = 0; /** diff --git a/includes/Storage/NameTableStore.php b/includes/Storage/NameTableStore.php index 4a02ede1778..782bc46190c 100644 --- a/includes/Storage/NameTableStore.php +++ b/includes/Storage/NameTableStore.php @@ -48,7 +48,7 @@ class NameTableStore { private $tableCache = null; /** @var bool|string */ - private $domain = false; + private $domain; /** @var int */ private $cacheTTL; @@ -60,9 +60,9 @@ class NameTableStore { /** @var string */ private $nameField; /** @var null|callable */ - private $normalizationCallback = null; + private $normalizationCallback; /** @var null|callable */ - private $insertCallback = null; + private $insertCallback; /** * @param ILoadBalancer $dbLoadBalancer A load balancer for acquiring database connections diff --git a/includes/api/ApiContinuationManager.php b/includes/api/ApiContinuationManager.php index 5ae6164031b..fb2c340bd47 100644 --- a/includes/api/ApiContinuationManager.php +++ b/includes/api/ApiContinuationManager.php @@ -27,7 +27,7 @@ class ApiContinuationManager { private $source; private $allModules = []; - private $generatedModules = []; + private $generatedModules; /** @var array[] */ private $continuationData = []; diff --git a/includes/api/ApiOpenSearchFormatJson.php b/includes/api/ApiOpenSearchFormatJson.php index b1903f20605..ab46074b93a 100644 --- a/includes/api/ApiOpenSearchFormatJson.php +++ b/includes/api/ApiOpenSearchFormatJson.php @@ -26,7 +26,7 @@ * @ingroup API */ class ApiOpenSearchFormatJson extends ApiFormatJson { - private $warningsAsError = false; + private $warningsAsError; public function __construct( ApiMain $main, $fm, $warningsAsError ) { parent::__construct( $main, "json$fm" ); diff --git a/includes/api/ApiPageSet.php b/includes/api/ApiPageSet.php index e8b0e13dc89..118ee32f9a9 100644 --- a/includes/api/ApiPageSet.php +++ b/includes/api/ApiPageSet.php @@ -47,7 +47,7 @@ class ApiPageSet extends ApiBase { private const DISABLE_GENERATORS = 1; private $mDbSource; - private $mParams = []; + private $mParams; private $mResolveRedirects; private $mConvertTitles; private $mAllowGenerator; @@ -82,7 +82,7 @@ class ApiPageSet extends ApiBase { /** @var array */ private $mRequestedPageFields = []; /** @var int */ - private $mDefaultNamespace = NS_MAIN; + private $mDefaultNamespace; /** @var callable|null */ private $mRedirectMergePolicy; diff --git a/includes/cache/localisation/LocalisationCache.php b/includes/cache/localisation/LocalisationCache.php index b60902db9e3..9f83d58ac11 100644 --- a/includes/cache/localisation/LocalisationCache.php +++ b/includes/cache/localisation/LocalisationCache.php @@ -51,7 +51,7 @@ class LocalisationCache { * Setting this reduces the overhead of cache freshness checking, which * requires doing a stat() for every extension i18n file. */ - private $manualRecache = false; + private $manualRecache; /** * The cache data. 3-d array, where the first key is the language code, diff --git a/includes/config/ServiceOptions.php b/includes/config/ServiceOptions.php index 1afcc2bd06e..acd4b9599e2 100644 --- a/includes/config/ServiceOptions.php +++ b/includes/config/ServiceOptions.php @@ -25,7 +25,7 @@ use Wikimedia\Assert\Assert; * @since 1.34 */ class ServiceOptions { - private $keys = []; + private $keys; private $options = []; /** diff --git a/includes/content/ContentHandlerFactory.php b/includes/content/ContentHandlerFactory.php index 89af8e6c69b..c9519d9b45a 100644 --- a/includes/content/ContentHandlerFactory.php +++ b/includes/content/ContentHandlerFactory.php @@ -46,7 +46,7 @@ final class ContentHandlerFactory implements IContentHandlerFactory { /** * @var string[]|callable[] */ - private $handlerSpecs = []; + private $handlerSpecs; /** * @var ContentHandler[] Registry of ContentHandler instances by model id diff --git a/includes/deferred/HtmlFileCacheUpdate.php b/includes/deferred/HtmlFileCacheUpdate.php index c159b928ed2..f572c1a54e6 100644 --- a/includes/deferred/HtmlFileCacheUpdate.php +++ b/includes/deferred/HtmlFileCacheUpdate.php @@ -30,7 +30,7 @@ use Wikimedia\Assert\Assert; */ class HtmlFileCacheUpdate implements DeferrableUpdate, MergeableUpdate { /** @var PageIdentity[] List of pages */ - private $pages = []; + private $pages; /** * @param PageIdentity[] $pages List of pages diff --git a/includes/filerepo/file/ForeignAPIFile.php b/includes/filerepo/file/ForeignAPIFile.php index 8fd159fe930..879e402afef 100644 --- a/includes/filerepo/file/ForeignAPIFile.php +++ b/includes/filerepo/file/ForeignAPIFile.php @@ -31,7 +31,7 @@ class ForeignAPIFile extends File { /** @var bool */ private $mExists; /** @var array */ - private $mInfo = []; + private $mInfo; protected $repoClass = ForeignAPIRepo::class; diff --git a/includes/filerepo/file/LocalFileRestoreBatch.php b/includes/filerepo/file/LocalFileRestoreBatch.php index c5afb0abbac..2b25ef3699c 100644 --- a/includes/filerepo/file/LocalFileRestoreBatch.php +++ b/includes/filerepo/file/LocalFileRestoreBatch.php @@ -41,7 +41,7 @@ class LocalFileRestoreBatch { private $all; /** @var bool Whether to remove all settings for suppressed fields */ - private $unsuppress = false; + private $unsuppress; /** * @param LocalFile $file diff --git a/includes/libs/ReplacementArray.php b/includes/libs/ReplacementArray.php index 46f9358b635..d40c028a505 100644 --- a/includes/libs/ReplacementArray.php +++ b/includes/libs/ReplacementArray.php @@ -22,7 +22,7 @@ * Wrapper around strtr() that holds replacements */ class ReplacementArray { - private $data = []; + private $data; /** * Create an object with the specified replacement array diff --git a/includes/libs/rdbms/lbfactory/LBFactorySimple.php b/includes/libs/rdbms/lbfactory/LBFactorySimple.php index 9bc3702cd90..ee0c49bdb6f 100644 --- a/includes/libs/rdbms/lbfactory/LBFactorySimple.php +++ b/includes/libs/rdbms/lbfactory/LBFactorySimple.php @@ -38,7 +38,7 @@ class LBFactorySimple extends LBFactory { private $loadMonitorConfig; /** @var array[] Map of (server index => server config map) */ - private $mainServers = []; + private $mainServers; /** @var array[][] Map of (cluster => server index => server config map) */ private $externalServersByCluster = []; diff --git a/includes/media/SVGReader.php b/includes/media/SVGReader.php index 78d284b7279..e42cb446ab0 100644 --- a/includes/media/SVGReader.php +++ b/includes/media/SVGReader.php @@ -35,8 +35,8 @@ class SVGReader { public const LANG_PREFIX_MATCH = 1; public const LANG_FULL_MATCH = 2; - /** @var null|XMLReader */ - private $reader = null; + /** @var XMLReader */ + private $reader; /** @var bool */ private $mDebug = false; diff --git a/includes/registration/VersionChecker.php b/includes/registration/VersionChecker.php index 1898ebd00de..880de730e92 100644 --- a/includes/registration/VersionChecker.php +++ b/includes/registration/VersionChecker.php @@ -43,17 +43,17 @@ class VersionChecker { /** * @var string[] List of installed PHP extensions */ - private $phpExtensions = []; + private $phpExtensions; /** * @var bool[] List of provided abilities */ - private $abilities = []; + private $abilities; /** * @var string[] List of provided ability errors */ - private $abilityErrors = []; + private $abilityErrors; /** * @var array Loaded extensions diff --git a/includes/session/SessionBackend.php b/includes/session/SessionBackend.php index 18a9dc2bac6..8d4c94e10b5 100644 --- a/includes/session/SessionBackend.php +++ b/includes/session/SessionBackend.php @@ -131,7 +131,7 @@ final class SessionBackend { private $delaySave = 0; /** @var bool */ - private $usePhpSessionHandling = true; + private $usePhpSessionHandling; /** @var bool */ private $checkPHPSessionRecursionGuard = false; diff --git a/includes/session/Token.php b/includes/session/Token.php index 4f717cbc34e..ec34608cc35 100644 --- a/includes/session/Token.php +++ b/includes/session/Token.php @@ -36,13 +36,13 @@ class Token { public const SUFFIX = '+\\'; /** @var string */ - private $secret = ''; + private $secret; /** @var string */ - private $salt = ''; + private $salt; /** @var bool */ - private $new = false; + private $new; /** * @param string $secret Token secret diff --git a/includes/skins/SkinFactory.php b/includes/skins/SkinFactory.php index bff8fd7be25..b63f24f033e 100644 --- a/includes/skins/SkinFactory.php +++ b/includes/skins/SkinFactory.php @@ -54,7 +54,7 @@ class SkinFactory { * * @var string[] */ - private $skipSkins = []; + private $skipSkins; /** * @internal For ServiceWiring only diff --git a/includes/specials/SpecialBotPasswords.php b/includes/specials/SpecialBotPasswords.php index 8ba5bca7434..76da7d88178 100644 --- a/includes/specials/SpecialBotPasswords.php +++ b/includes/specials/SpecialBotPasswords.php @@ -44,7 +44,7 @@ class SpecialBotPasswords extends FormSpecialPage { private $password = null; /** @var Psr\Log\LoggerInterface */ - private $logger = null; + private $logger; /** @var PasswordFactory */ private $passwordFactory; diff --git a/includes/specials/helpers/ImportReporter.php b/includes/specials/helpers/ImportReporter.php index 166e4c1800b..a9efe477cc6 100644 --- a/includes/specials/helpers/ImportReporter.php +++ b/includes/specials/helpers/ImportReporter.php @@ -28,10 +28,10 @@ use MediaWiki\MediaWikiServices; class ImportReporter extends ContextSource { use ProtectedHookAccessorTrait; - private $reason = false; + private $reason; private $logTags = []; - private $mOriginalLogCallback = null; - private $mOriginalPageOutCallback = null; + private $mOriginalLogCallback; + private $mOriginalPageOutCallback; private $mLogItemCount = 0; private $mPageCount; private $mIsUpload; diff --git a/includes/specials/pagers/ContribsPager.php b/includes/specials/pagers/ContribsPager.php index 05abd1ff818..e8f2c1d9027 100644 --- a/includes/specials/pagers/ContribsPager.php +++ b/includes/specials/pagers/ContribsPager.php @@ -51,7 +51,7 @@ class ContribsPager extends RangeChronologicalPager { /** * @var string|int A single namespace number, or an empty string for all namespaces */ - private $namespace = ''; + private $namespace; /** * @var string|false Name of tag to filter, or false to ignore tags diff --git a/includes/title/MalformedTitleException.php b/includes/title/MalformedTitleException.php index afd58fdac52..c0c66f2ea2e 100644 --- a/includes/title/MalformedTitleException.php +++ b/includes/title/MalformedTitleException.php @@ -24,9 +24,13 @@ * @since 1.23 */ class MalformedTitleException extends Exception implements ILocalizedException { - private $titleText = null; - private $errorMessage = null; - private $errorMessageParameters = []; + + /** @var string|null */ + private $titleText; + /** @var string */ + private $errorMessage; + /** @var array */ + private $errorMessageParameters; /** * @stable to call diff --git a/includes/user/BotPassword.php b/includes/user/BotPassword.php index 5d2f3006138..b29df06b90e 100644 --- a/includes/user/BotPassword.php +++ b/includes/user/BotPassword.php @@ -68,8 +68,8 @@ class BotPassword implements IDBAccessObject { /** @var string[] */ private $grants; - /** @var int */ - private $flags = self::READ_NORMAL; + /** @var int Defaults to {@see READ_NORMAL} */ + private $flags; /** * @param stdClass $row bot_passwords database row diff --git a/includes/user/ExternalUserNames.php b/includes/user/ExternalUserNames.php index f4afc8cec77..a6e0b06c785 100644 --- a/includes/user/ExternalUserNames.php +++ b/includes/user/ExternalUserNames.php @@ -31,12 +31,12 @@ class ExternalUserNames { /** * @var string */ - private $usernamePrefix = 'imported'; + private $usernamePrefix; /** * @var bool */ - private $assignKnownUsers = false; + private $assignKnownUsers; /** * @var bool[] diff --git a/tests/phpunit/mocks/TestLogger.php b/tests/phpunit/mocks/TestLogger.php index 7152f62b2bf..daf2f41703b 100644 --- a/tests/phpunit/mocks/TestLogger.php +++ b/tests/phpunit/mocks/TestLogger.php @@ -31,8 +31,8 @@ use Psr\Log\LogLevel; * @since 1.27 */ class TestLogger extends \Psr\Log\AbstractLogger { - private $collect = false; - private $collectContext = false; + private $collect; + private $collectContext; private $buffer = []; /** @var callable|null */ private $filter; diff --git a/tests/phpunit/suites/ParserIntegrationTest.php b/tests/phpunit/suites/ParserIntegrationTest.php index 83211449518..78e81cd28f7 100644 --- a/tests/phpunit/suites/ParserIntegrationTest.php +++ b/tests/phpunit/suites/ParserIntegrationTest.php @@ -37,7 +37,7 @@ class ParserIntegrationTest extends PHPUnit\Framework\TestCase { private $ptRunner; /** @var string|null */ - private $skipMessage = null; + private $skipMessage; public function __construct( $runner, $fileName, $test, $skipMessage = null ) { parent::__construct( 'testParse', [ ( $test['parsoid'] ?? false ) ? 'parsoid' : 'legacy parser' ],