From 864068d00087b62b12d8088faefa8638fe6f5519 Mon Sep 17 00:00:00 2001 From: Umherirrender Date: Tue, 17 Aug 2021 21:52:34 +0200 Subject: [PATCH] Remove unneeded explicit true/false inside conditions The non-strict conditions in if/while are true/false without the check. In some situation the true/false is removed, because it is known to be a bool (by is_bool check or type hint) Change-Id: I5ca4c4771af25d2e785e82732df204a73653886e --- includes/EditPage.php | 8 ++++---- includes/Linker.php | 4 ++-- includes/actions/RollbackAction.php | 2 +- includes/actions/ViewAction.php | 2 +- includes/filerepo/file/LocalFile.php | 6 +++--- includes/htmlform/fields/HTMLMultiSelectField.php | 2 +- includes/htmlform/fields/HTMLTextAreaField.php | 2 +- includes/htmlform/fields/HTMLTextField.php | 2 +- includes/installer/WebInstaller.php | 2 +- includes/libs/rdbms/dbal/TimestampType.php | 2 +- includes/registration/VersionChecker.php | 2 +- includes/search/SearchResultSet.php | 2 +- includes/upload/UploadBase.php | 4 ++-- maintenance/Sqlite.php | 2 +- maintenance/deleteAutoPatrolLogs.php | 2 +- 15 files changed, 22 insertions(+), 22 deletions(-) diff --git a/includes/EditPage.php b/includes/EditPage.php index 2c1a9f0a71b..7d1b2f14a7d 100644 --- a/includes/EditPage.php +++ b/includes/EditPage.php @@ -2031,7 +2031,7 @@ class EditPage implements IEditObject { ); // Check the constraints - if ( $constraintRunner->checkConstraints() === false ) { + if ( !$constraintRunner->checkConstraints() ) { $failed = $constraintRunner->getFailedConstraint(); // Need to check SpamRegexConstraint here, to avoid needing to pass @@ -2081,7 +2081,7 @@ class EditPage implements IEditObject { ); // Check the constraints - if ( $constraintRunner->checkConstraints() === false ) { + if ( !$constraintRunner->checkConstraints() ) { $failed = $constraintRunner->getFailedConstraint(); $this->handleFailedConstraint( $failed ); return Status::wrap( $failed->getLegacyStatus() ); @@ -2261,7 +2261,7 @@ class EditPage implements IEditObject { ); } // Check the constraints - if ( $constraintRunner->checkConstraints() === false ) { + if ( !$constraintRunner->checkConstraints() ) { $failed = $constraintRunner->getFailedConstraint(); $this->handleFailedConstraint( $failed ); return Status::wrap( $failed->getLegacyStatus() ); @@ -2319,7 +2319,7 @@ class EditPage implements IEditObject { ) ); // Check the constraints - if ( $constraintRunner->checkConstraints() === false ) { + if ( !$constraintRunner->checkConstraints() ) { $failed = $constraintRunner->getFailedConstraint(); $this->handleFailedConstraint( $failed ); return Status::wrap( $failed->getLegacyStatus() ); diff --git a/includes/Linker.php b/includes/Linker.php index 577254c7eec..d3bde055712 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -453,7 +453,7 @@ class Linker { $label = $frameParams['title']; } $s = self::makeBrokenImageLinkObj( - $title, $label, '', '', '', $time == true, $handlerParams + $title, $label, '', '', '', (bool)$time, $handlerParams ); } else { self::processResponsiveImages( $file, $thumb, $handlerParams ); @@ -713,7 +713,7 @@ class Linker { $label = $frameParams['title']; } $s .= self::makeBrokenImageLinkObj( - $title, $label, '', '', '', $time == true, $handlerParams + $title, $label, '', '', '', (bool)$time, $handlerParams ); $zoomIcon = ''; } elseif ( !$thumb ) { diff --git a/includes/actions/RollbackAction.php b/includes/actions/RollbackAction.php index b6b34d57b5e..611e4e0338e 100644 --- a/includes/actions/RollbackAction.php +++ b/includes/actions/RollbackAction.php @@ -120,7 +120,7 @@ class RollbackAction extends FormAction { * @throws ThrottledError */ public function show() { - if ( $this->getUser()->getOption( 'showrollbackconfirmation' ) == false || + if ( !$this->getUser()->getOption( 'showrollbackconfirmation' ) || $this->getRequest()->wasPosted() ) { $this->handleRollbackRequest(); } else { diff --git a/includes/actions/ViewAction.php b/includes/actions/ViewAction.php index 957e6470d3a..9ec73b9650b 100644 --- a/includes/actions/ViewAction.php +++ b/includes/actions/ViewAction.php @@ -47,7 +47,7 @@ class ViewAction extends FormlessAction { MediaWikiServices::getInstance()->getHookContainer()->emitDeprecationWarnings(); if ( - $config->get( 'DebugToolbar' ) == false && // don't let this get stuck on pages + !$config->get( 'DebugToolbar' ) && // don't let this get stuck on pages $this->getWikiPage()->checkTouched() // page exists and is not a redirect ) { // Include any redirect in the last-modified calculation diff --git a/includes/filerepo/file/LocalFile.php b/includes/filerepo/file/LocalFile.php index e8824e465ca..d28b15cf82e 100644 --- a/includes/filerepo/file/LocalFile.php +++ b/includes/filerepo/file/LocalFile.php @@ -2005,9 +2005,9 @@ class LocalFile extends File { $wikiPage->setFile( $this ); // Determine log action. If reupload is done by reverting, use a special log_action. - if ( $revert === true ) { + if ( $revert ) { $logAction = 'revert'; - } elseif ( $reupload === true ) { + } elseif ( $reupload ) { $logAction = 'overwrite'; } else { $logAction = 'upload'; @@ -2035,7 +2035,7 @@ class LocalFile extends File { $logId = $logEntry->insert(); if ( $descTitle->exists() ) { - if ( $createNullRevision !== false ) { + if ( $createNullRevision ) { $revStore = MediaWikiServices::getInstance()->getRevisionStore(); // Use own context to get the action text in content language $formatter = LogFormatter::newFromEntry( $logEntry ); diff --git a/includes/htmlform/fields/HTMLMultiSelectField.php b/includes/htmlform/fields/HTMLMultiSelectField.php index 0105f508878..5393b5248a1 100644 --- a/includes/htmlform/fields/HTMLMultiSelectField.php +++ b/includes/htmlform/fields/HTMLMultiSelectField.php @@ -22,7 +22,7 @@ class HTMLMultiSelectField extends HTMLFormField implements HTMLNestedFilterable parent::__construct( $params ); // If the disabled-options parameter is not provided, use an empty array - if ( isset( $this->mParams['disabled-options'] ) === false ) { + if ( !isset( $this->mParams['disabled-options'] ) ) { $this->mParams['disabled-options'] = []; } diff --git a/includes/htmlform/fields/HTMLTextAreaField.php b/includes/htmlform/fields/HTMLTextAreaField.php index 2b58eec47ca..44699922b7d 100644 --- a/includes/htmlform/fields/HTMLTextAreaField.php +++ b/includes/htmlform/fields/HTMLTextAreaField.php @@ -45,7 +45,7 @@ class HTMLTextAreaField extends HTMLFormField { $val = $this->mParams['spellcheck'] ?? null; if ( is_bool( $val ) ) { // "spellcheck" attribute literally requires "true" or "false" to work. - return $val === true ? 'true' : 'false'; + return $val ? 'true' : 'false'; } return null; } diff --git a/includes/htmlform/fields/HTMLTextField.php b/includes/htmlform/fields/HTMLTextField.php index 0c7c365a754..62660707426 100644 --- a/includes/htmlform/fields/HTMLTextField.php +++ b/includes/htmlform/fields/HTMLTextField.php @@ -55,7 +55,7 @@ class HTMLTextField extends HTMLFormField { $val = $this->mParams['spellcheck'] ?? null; if ( is_bool( $val ) ) { // "spellcheck" attribute literally requires "true" or "false" to work. - return $val === true ? 'true' : 'false'; + return $val ? 'true' : 'false'; } return null; } diff --git a/includes/installer/WebInstaller.php b/includes/installer/WebInstaller.php index 1a36e1ae81d..1eb4d64de03 100644 --- a/includes/installer/WebInstaller.php +++ b/includes/installer/WebInstaller.php @@ -654,7 +654,7 @@ class WebInstaller extends Installer { $html = ( $text instanceof HtmlArmor ) ? HtmlArmor::getHtml( $text ) : $this->parse( $text, true ); - $icon = ( $icon == false ) ? + $icon = ( !$icon ) ? 'images/info-32.png' : 'images/' . $icon; $alt = wfMessage( 'config-information' )->text(); diff --git a/includes/libs/rdbms/dbal/TimestampType.php b/includes/libs/rdbms/dbal/TimestampType.php index c3b25c464f3..255d87c2b27 100644 --- a/includes/libs/rdbms/dbal/TimestampType.php +++ b/includes/libs/rdbms/dbal/TimestampType.php @@ -15,7 +15,7 @@ class TimestampType extends Type { public function getSQLDeclaration( array $fieldDeclaration, AbstractPlatform $platform ) { if ( $platform->getName() == 'mysql' ) { // "infinite" (in expiry values has to be VARBINARY) - if ( isset( $fieldDeclaration['allowInfinite'] ) && $fieldDeclaration['allowInfinite'] == true ) { + if ( isset( $fieldDeclaration['allowInfinite'] ) && $fieldDeclaration['allowInfinite'] ) { return 'VARBINARY(14)'; } return 'BINARY(14)'; diff --git a/includes/registration/VersionChecker.php b/includes/registration/VersionChecker.php index 880de730e92..a047e118e29 100644 --- a/includes/registration/VersionChecker.php +++ b/includes/registration/VersionChecker.php @@ -222,7 +222,7 @@ class VersionChecker { . 'in ' . $extension ); } - if ( $constraint === true && + if ( $constraint && $this->abilities[$ability] !== true ) { // add custom error message for missing ability if specified diff --git a/includes/search/SearchResultSet.php b/includes/search/SearchResultSet.php index fe5537f16ae..90cd198af34 100644 --- a/includes/search/SearchResultSet.php +++ b/includes/search/SearchResultSet.php @@ -210,7 +210,7 @@ class SearchResultSet extends BaseSearchResultSet { return $this->results; } $this->rewind(); - while ( ( $result = $this->next() ) != false ) { + while ( $result = $this->next() ) { $this->results[] = $result; } $this->rewind(); diff --git a/includes/upload/UploadBase.php b/includes/upload/UploadBase.php index 064bb5a93ab..cba353a20f3 100644 --- a/includes/upload/UploadBase.php +++ b/includes/upload/UploadBase.php @@ -1291,7 +1291,7 @@ abstract class UploadBase { return true; } - } elseif ( $match === true ) { + } elseif ( $match ) { wfDebug( __METHOD__ . ": mime type $mime matches extension $extension, passing file" ); /** @todo If it's a bitmap, make sure PHP or ImageMagick resp. can handle it! */ @@ -2039,7 +2039,7 @@ abstract class UploadBase { return [ 'warning' => 'page-exists', 'file' => $file ]; } - if ( strpos( $file->getName(), '.' ) == false ) { + if ( !strpos( $file->getName(), '.' ) ) { $partname = $file->getName(); $extension = ''; } else { diff --git a/maintenance/Sqlite.php b/maintenance/Sqlite.php index 91778376bfb..8fb3b1bafae 100644 --- a/maintenance/Sqlite.php +++ b/maintenance/Sqlite.php @@ -67,7 +67,7 @@ class Sqlite { try { foreach ( $files as $file ) { $err = $db->sourceFile( $file ); - if ( $err != true ) { + if ( $err ) { return $err; } } diff --git a/maintenance/deleteAutoPatrolLogs.php b/maintenance/deleteAutoPatrolLogs.php index 989448349a8..6f122239c09 100644 --- a/maintenance/deleteAutoPatrolLogs.php +++ b/maintenance/deleteAutoPatrolLogs.php @@ -175,7 +175,7 @@ class DeleteAutoPatrolLogs extends Maintenance { continue; } - if ( $auto === true ) { + if ( $auto ) { $autopatrols[] = $row->log_id; } }