Move property initialisation out of the constructor

When the value is a constant, the initialization can be done
way up together with the property declaration. I believe
this makes the code easier to read because it's not spread
out so much.

Change-Id: I5af482feccb746c144c0f318e119165cf5a56cbe
This commit is contained in:
Thiemo Kreuz 2021-05-12 10:52:47 +02:00 committed by Krinkle
parent 3843d16823
commit e2a2a393f9
6 changed files with 10 additions and 21 deletions

View file

@ -55,7 +55,7 @@ class EditFilterMergedContentHookConstraint implements IEditConstraint {
private $status;
/** @var string */
private $hookError;
private $hookError = '';
/**
* @param HookContainer $hookContainer
@ -77,7 +77,6 @@ class EditFilterMergedContentHookConstraint implements IEditConstraint {
$this->summary = $summary;
$this->minorEdit = $minorEdit;
$this->status = Status::newGood();
$this->hookError = '';
}
public function checkConstraint(): string {

View file

@ -124,10 +124,10 @@ class LocalFile extends File {
protected $sha1;
/** @var bool Whether or not core data has been loaded from the database (loadFromXxx) */
protected $dataLoaded;
protected $dataLoaded = false;
/** @var bool Whether or not lazy-loaded data has been loaded from the database */
protected $extraDataLoaded;
protected $extraDataLoaded = false;
/** @var int Bitfield akin to rev_deleted */
protected $deleted;
@ -136,10 +136,10 @@ class LocalFile extends File {
protected $repoClass = LocalRepo::class;
/** @var int Number of line to return by nextHistoryLine() (constructor) */
private $historyLine;
private $historyLine = 0;
/** @var IResultWrapper|null Result of the query for the file's history (nextHistoryLine) */
private $historyRes;
private $historyRes = null;
/** @var string Major MIME type */
private $major_mime;
@ -315,11 +315,6 @@ class LocalFile extends File {
public function __construct( $title, $repo ) {
parent::__construct( $title, $repo );
$this->historyLine = 0;
$this->historyRes = null;
$this->dataLoaded = false;
$this->extraDataLoaded = false;
$this->assertRepoDefined();
$this->assertTitleDefined();
}

View file

@ -36,14 +36,13 @@ class ImportStringSource implements ImportSource {
private $mString;
/** @var bool */
private $mRead;
private $mRead = false;
/**
* @param string $string
*/
public function __construct( $string ) {
$this->mString = $string;
$this->mRead = false;
}
/**

View file

@ -34,7 +34,7 @@ class ImportReporter extends ContextSource {
private $mOriginalLogCallback;
private $mOriginalPageOutCallback;
private $mLogItemCount = 0;
private $mPageCount;
private $mPageCount = 0;
private $mIsUpload;
private $mInterwiki;
@ -50,7 +50,6 @@ class ImportReporter extends ContextSource {
$this->mOriginalLogCallback =
$importer->setLogItemCallback( [ $this, 'reportLogItem' ] );
$importer->setNoticeCallback( [ $this, 'reportNotice' ] );
$this->mPageCount = 0;
$this->mIsUpload = $upload;
$this->mInterwiki = $interwiki;
$this->reason = $reason;

View file

@ -40,7 +40,7 @@ class CompareParsers extends DumpIterator {
private $count = 0;
/** @var bool */
private $saveFailed;
private $saveFailed = false;
/** @var bool */
private $stripParametersEnabled;
/** @var bool */
@ -54,7 +54,6 @@ class CompareParsers extends DumpIterator {
public function __construct() {
parent::__construct();
$this->saveFailed = false;
$this->addDescription( 'Run a file or dump with several parsers' );
$this->addOption( 'parser1', 'The first parser to compare.', true, true );
$this->addOption( 'parser2', 'The second parser to compare.', true, true );

View file

@ -5,9 +5,9 @@ class TestFileEditor {
private $numLines;
private $deletions;
private $changes;
private $pos;
private $pos = 0;
private $warningCallback;
private $result;
private $result = '';
public static function edit( $text, array $deletions, array $changes, $warningCallback = null ) {
$editor = new self( $text, $deletions, $changes, $warningCallback );
@ -20,9 +20,7 @@ class TestFileEditor {
$this->numLines = count( $this->lines );
$this->deletions = array_fill_keys( $deletions, true );
$this->changes = $changes;
$this->pos = 0;
$this->warningCallback = $warningCallback;
$this->result = '';
}
private function execute() {