From f2c1beec44174a94415cb312e6d5db37bf8565e7 Mon Sep 17 00:00:00 2001 From: Daimona Eaytoy Date: Sun, 26 Aug 2018 10:34:42 +0200 Subject: [PATCH] Replace double-equals with triple-equals Since double-equals are evil. I left some of them in place where I wasn't sure, but I may be changed some which were intended to be doubles. It could be a good idea to delay merging this patch until we'll have more code coverage. Change-Id: I1721a3ba532d481e3ecf35f51099c1438b6b73b2 --- includes/AFComputedVariable.php | 6 +- includes/AbuseFilter.php | 29 +++-- includes/AbuseFilterHooks.php | 12 +- .../AbuseFilterPreAuthenticationProvider.php | 2 +- includes/Views/AbuseFilterViewDiff.php | 8 +- includes/Views/AbuseFilterViewEdit.php | 38 +++--- includes/Views/AbuseFilterViewExamine.php | 2 +- includes/Views/AbuseFilterViewList.php | 12 +- includes/Views/AbuseFilterViewRevert.php | 2 +- includes/Views/AbuseFilterViewTestBatch.php | 2 +- includes/pagers/AbuseFilterHistoryPager.php | 2 +- includes/parser/AFPData.php | 78 ++++++------- includes/parser/AFPTreeNode.php | 2 +- includes/parser/AFPTreeParser.php | 76 ++++++------ includes/parser/AbuseFilterCachingParser.php | 10 +- includes/parser/AbuseFilterParser.php | 110 +++++++++--------- includes/parser/AbuseFilterTokenizer.php | 2 +- includes/special/SpecialAbuseFilter.php | 26 ++--- includes/special/SpecialAbuseLog.php | 12 +- maintenance/addMissingLoggingEntries.php | 2 +- tests/legacyParserTest.php | 4 +- 21 files changed, 219 insertions(+), 218 deletions(-) diff --git a/includes/AFComputedVariable.php b/includes/AFComputedVariable.php index 1ae799571..f8fb52492 100644 --- a/includes/AFComputedVariable.php +++ b/includes/AFComputedVariable.php @@ -258,10 +258,10 @@ class AFComputedVariable { $oldLinks = explode( "\n", $oldLinks ); $newLinks = explode( "\n", $newLinks ); - if ( $this->mMethod == 'link-diff-added' ) { + if ( $this->mMethod === 'link-diff-added' ) { $result = array_diff( $newLinks, $oldLinks ); } - if ( $this->mMethod == 'link-diff-removed' ) { + if ( $this->mMethod === 'link-diff-removed' ) { $result = array_diff( $oldLinks, $newLinks ); } break; @@ -366,7 +366,7 @@ class AFComputedVariable { $asOf = $parameters['asof']; $obj = self::getUserObject( $user ); - if ( $obj->getId() == 0 ) { + if ( $obj->getId() === 0 ) { $result = 0; break; } diff --git a/includes/AbuseFilter.php b/includes/AbuseFilter.php index 304db33c9..6142fcf71 100644 --- a/includes/AbuseFilter.php +++ b/includes/AbuseFilter.php @@ -250,7 +250,7 @@ class AbuseFilter { $msg = $context->msg( $msgName )->parse(); $title = Title::newFromText( $page ); - if ( $name == $pageType ) { + if ( $name === $pageType ) { $links[] = Xml::tags( 'strong', null, $msg ); } else { $links[] = $linkRenderer->makeLink( $title, new HtmlArmor( $msg ) ); @@ -902,7 +902,7 @@ class AbuseFilter { && !empty( $wgAbuseFilterRestrictions[$row->afa_consequence] ) ) { // Don't do the action - } elseif ( $row->afa_filter != $row->af_id ) { + } elseif ( $row->afa_filter !== $row->af_id ) { // We probably got a NULL, as it's a LEFT JOIN. Don't add it. } else { $actionsByFilter[$prefix . $row->afa_filter][$row->afa_consequence] = [ @@ -1209,7 +1209,7 @@ class AbuseFilter { self::recordRuntimeProfilingResult( count( $matched_filters ), $condCount, $runtime ); } - if ( count( $matched_filters ) == 0 ) { + if ( count( $matched_filters ) === 0 ) { $status = Status::newGood(); } else { $status = self::executeFilterActions( $matched_filters, $title, $vars, $user ); @@ -1234,7 +1234,7 @@ class AbuseFilter { ]; // Hack to avoid revealing IPs of people creating accounts - if ( !$user->getId() && ( $action == 'createaccount' || $action == 'autocreateaccount' ) ) { + if ( !$user->getId() && ( $action === 'createaccount' || $action === 'autocreateaccount' ) ) { $log_template['afl_user_text'] = $vars->getVar( 'accountname' )->toString(); } @@ -1388,7 +1388,7 @@ class AbuseFilter { $thisLog['afl_actions'] = implode( ',', $actions ); // Don't log if we were only throttling. - if ( $thisLog['afl_actions'] != 'throttle' ) { + if ( $thisLog['afl_actions'] !== 'throttle' ) { $log_rows[] = $thisLog; // Global logging if ( $globalIndex ) { @@ -2409,8 +2409,7 @@ class AbuseFilter { } // Don't allow setting as deleted an active filter - if ( $request->getCheck( 'wpFilterEnabled' ) == true && - $request->getCheck( 'wpFilterDeleted' ) == true ) { + if ( $request->getCheck( 'wpFilterEnabled' ) && $request->getCheck( 'wpFilterDeleted' ) ) { $validationStatus->error( 'abusefilter-edit-deleting-enabled' ); return $validationStatus; } @@ -2535,7 +2534,7 @@ class AbuseFilter { $dbw->startAtomic( __METHOD__ ); // Insert MAIN row. - if ( $filter == 'new' ) { + if ( $filter === 'new' ) { $new_id = null; $is_new = true; } else { @@ -2623,7 +2622,7 @@ class AbuseFilter { // Do the update $dbw->insert( 'abuse_filter_history', $afh_row, __METHOD__ ); $history_id = $dbw->insertId(); - if ( $filter != 'new' ) { + if ( $filter !== 'new' ) { $dbw->delete( 'abuse_filter_action', [ 'afa_filter' => $filter ], @@ -2637,7 +2636,7 @@ class AbuseFilter { // Invalidate cache if this was a global rule if ( $wasGlobal || $newRow['af_global'] ) { $group = 'default'; - if ( isset( $newRow['af_group'] ) && $newRow['af_group'] != '' ) { + if ( isset( $newRow['af_group'] ) && $newRow['af_group'] !== '' ) { $group = $newRow['af_group']; } @@ -2781,11 +2780,11 @@ class AbuseFilter { * @return AbuseFilterVariableHolder|null */ public static function getVarsFromRCRow( $row ) { - if ( $row->rc_log_type == 'move' ) { + if ( $row->rc_log_type === 'move' ) { $vars = self::getMoveVarsFromRCRow( $row ); - } elseif ( $row->rc_log_type == 'newusers' ) { + } elseif ( $row->rc_log_type === 'newusers' ) { $vars = self::getCreateVarsFromRCRow( $row ); - } elseif ( $row->rc_log_type == 'delete' ) { + } elseif ( $row->rc_log_type === 'delete' ) { $vars = self::getDeleteVarsFromRCRow( $row ); } elseif ( $row->rc_log_type == 'upload' ) { $vars = self::getUploadVarsFromRCRow( $row ); @@ -2810,13 +2809,13 @@ class AbuseFilter { public static function getCreateVarsFromRCRow( $row ) { $vars = new AbuseFilterVariableHolder; - $vars->setVar( 'action', ( $row->rc_log_action == 'autocreate' ) ? + $vars->setVar( 'action', ( $row->rc_log_action === 'autocreate' ) ? 'autocreateaccount' : 'createaccount' ); $name = Title::makeTitle( $row->rc_namespace, $row->rc_title )->getText(); // Add user data if the account was created by a registered user - if ( $row->rc_user && $name != $row->rc_user_text ) { + if ( $row->rc_user && $name !== $row->rc_user_text ) { $user = User::newFromName( $row->rc_user_text ); $vars->addHolders( self::generateUserVars( $user ) ); } diff --git a/includes/AbuseFilterHooks.php b/includes/AbuseFilterHooks.php index 07cd91cf6..312bb4dd9 100644 --- a/includes/AbuseFilterHooks.php +++ b/includes/AbuseFilterHooks.php @@ -116,7 +116,7 @@ class AbuseFilterHooks { if ( $content->equals( $oldContent ) ) { return Status::newGood(); } - } elseif ( strcmp( $oldAfText, $text ) == 0 ) { + } elseif ( strcmp( $oldAfText, $text ) === 0 ) { // Otherwise, compare strings return Status::newGood(); } @@ -521,8 +521,8 @@ class AbuseFilterHooks { public static function onLoadExtensionSchemaUpdates( DatabaseUpdater $updater ) { $dir = dirname( __DIR__ ); - if ( $updater->getDB()->getType() == 'mysql' || $updater->getDB()->getType() == 'sqlite' ) { - if ( $updater->getDB()->getType() == 'mysql' ) { + if ( $updater->getDB()->getType() === 'mysql' || $updater->getDB()->getType() === 'sqlite' ) { + if ( $updater->getDB()->getType() === 'mysql' ) { $updater->addExtensionUpdate( [ 'addTable', 'abuse_filter', "$dir/abusefilter.tables.sql", true ] ); $updater->addExtensionUpdate( [ 'addTable', 'abuse_filter_history', @@ -545,7 +545,7 @@ class AbuseFilterHooks { "$dir/db_patches/patch-global_filters.sql", true ] ); $updater->addExtensionUpdate( [ 'addField', 'abuse_filter_log', 'afl_rev_id', "$dir/db_patches/patch-afl_action_id.sql", true ] ); - if ( $updater->getDB()->getType() == 'mysql' ) { + if ( $updater->getDB()->getType() === 'mysql' ) { $updater->addExtensionUpdate( [ 'addIndex', 'abuse_filter_log', 'filter_timestamp', "$dir/db_patches/patch-fix-indexes.sql", true ] ); } else { @@ -558,7 +558,7 @@ class AbuseFilterHooks { $updater->addExtensionUpdate( [ 'addField', 'abuse_filter', 'af_group', "$dir/db_patches/patch-af_group.sql", true ] ); - if ( $updater->getDB()->getType() == 'mysql' ) { + if ( $updater->getDB()->getType() === 'mysql' ) { $updater->addExtensionUpdate( [ 'addIndex', 'abuse_filter_log', 'wiki_timestamp', "$dir/db_patches/patch-global_logging_wiki-index.sql", true @@ -577,7 +577,7 @@ class AbuseFilterHooks { "$dir/db_patches/patch-afl-namespace_int.sqlite.sql", true ] ); } - } elseif ( $updater->getDB()->getType() == 'postgres' ) { + } elseif ( $updater->getDB()->getType() === 'postgres' ) { $updater->addExtensionUpdate( [ 'addTable', 'abuse_filter', "$dir/abusefilter.tables.pg.sql", true ] ); $updater->addExtensionUpdate( [ diff --git a/includes/AbuseFilterPreAuthenticationProvider.php b/includes/AbuseFilterPreAuthenticationProvider.php index 832085608..0d3b7bb78 100644 --- a/includes/AbuseFilterPreAuthenticationProvider.php +++ b/includes/AbuseFilterPreAuthenticationProvider.php @@ -35,7 +35,7 @@ class AbuseFilterPreAuthenticationProvider extends AbstractPreAuthenticationProv * @return StatusValue */ protected function testUser( $user, $creator, $autocreate ) { - if ( $user->getName() == wfMessage( 'abusefilter-blocker' )->inContentLanguage()->text() ) { + if ( $user->getName() === wfMessage( 'abusefilter-blocker' )->inContentLanguage()->text() ) { return StatusValue::newFatal( 'abusefilter-accountreserved' ); } diff --git a/includes/Views/AbuseFilterViewDiff.php b/includes/Views/AbuseFilterViewDiff.php index 86480a8a8..59aa49fda 100644 --- a/includes/Views/AbuseFilterViewDiff.php +++ b/includes/Views/AbuseFilterViewDiff.php @@ -166,7 +166,7 @@ class AbuseFilterViewDiff extends AbuseFilterView { [ 'afh_id' => $spec, 'afh_filter' => $this->mFilter ], __METHOD__ ); - } elseif ( $spec == 'cur' ) { + } elseif ( $spec === 'cur' ) { $row = $dbr->selectRow( 'abuse_filter_history', $selectFields, @@ -174,7 +174,9 @@ class AbuseFilterViewDiff extends AbuseFilterView { __METHOD__, [ 'ORDER BY' => 'afh_timestamp desc' ] ); - } elseif ( ( $spec == 'prev' || $spec == 'next' ) && !in_array( $otherSpec, $dependentSpecs ) ) { + } elseif ( ( $spec === 'prev' || $spec === 'next' ) && + !in_array( $otherSpec, $dependentSpecs ) + ) { // cached $other = $this->loadSpec( $otherSpec, $spec ); @@ -301,7 +303,7 @@ class AbuseFilterViewDiff extends AbuseFilterView { ); if ( count( $this->getConfig()->get( 'AbuseFilterValidGroups' ) ) > 1 || - $oldVersion['info']['group'] != $newVersion['info']['group'] + $oldVersion['info']['group'] !== $newVersion['info']['group'] ) { $info .= $this->getDiffRow( 'abusefilter-edit-group', diff --git a/includes/Views/AbuseFilterViewEdit.php b/includes/Views/AbuseFilterViewEdit.php index e58b6ee9a..bb39f8d17 100644 --- a/includes/Views/AbuseFilterViewEdit.php +++ b/includes/Views/AbuseFilterViewEdit.php @@ -44,7 +44,7 @@ class AbuseFilterViewEdit extends AbuseFilterView { // Add the default warning and disallow messages in a JS variable $this->exposeMessages(); - if ( $filter == 'new' && !$this->canEdit() ) { + if ( $filter === 'new' && !$this->canEdit() ) { $out->addHTML( Xml::tags( 'p', @@ -189,7 +189,7 @@ class AbuseFilterViewEdit extends AbuseFilterView { $fields = []; $fields['abusefilter-edit-id'] = - $this->mFilter == 'new' ? + $this->mFilter === 'new' ? $this->msg( 'abusefilter-edit-new' )->escaped() : $lang->formatNum( $filter ); $fields['abusefilter-edit-description'] = @@ -326,19 +326,19 @@ class AbuseFilterViewEdit extends AbuseFilterView { 'align' => 'inline', ]; - if ( $checkboxId == 'global' && !$this->canEditGlobal() ) { + if ( $checkboxId === 'global' && !$this->canEditGlobal() ) { $checkboxAttribs['disabled'] = 'disabled'; } // Set readonly on deleted if the filter isn't disabled - if ( $checkboxId == 'deleted' && $row->af_enabled == 1 ) { + if ( $checkboxId === 'deleted' && $row->af_enabled == 1 ) { $checkboxAttribs['disabled'] = 'disabled'; } // Add infusable where needed - if ( $checkboxId == 'deleted' || $checkboxId == 'enabled' ) { + if ( $checkboxId === 'deleted' || $checkboxId === 'enabled' ) { $checkboxAttribs['infusable'] = true; - if ( $checkboxId == 'deleted' ) { + if ( $checkboxId === 'deleted' ) { $labelAttribs['id'] = $postVar . 'Label'; $labelAttribs['infusable'] = true; } @@ -355,7 +355,7 @@ class AbuseFilterViewEdit extends AbuseFilterView { $fields['abusefilter-edit-flags'] = $flags; $tools = ''; - if ( $filter != 'new' ) { + if ( $filter !== 'new' ) { if ( $user->isAllowed( 'abusefilter-revert' ) ) { $tools .= Xml::tags( 'p', null, @@ -854,7 +854,7 @@ class AbuseFilterViewEdit extends AbuseFilterView { new OOUI\CheckboxInputWidget( [ 'name' => 'wpFilterBlockTalk', 'id' => 'mw-abusefilter-action-checkbox-blocktalk', - 'selected' => isset( $blockTalk ) && $blockTalk == 'blocktalk', + 'selected' => isset( $blockTalk ) && $blockTalk === 'blocktalk', 'classes' => [ 'mw-abusefilter-action-checkbox' ], 'disabled' => $readOnly ] @@ -944,7 +944,7 @@ class AbuseFilterViewEdit extends AbuseFilterView { // mw-abusefilter-warn-message-existing, mw-abusefilter-disallow-message-existing 'id' => "mw-abusefilter-$formId-message-existing", // abusefilter-warning, abusefilter-disallowed - 'value' => $warnMsg == "abusefilter-$action" ? "abusefilter-$action" : 'other', + 'value' => $warnMsg === "abusefilter-$action" ? "abusefilter-$action" : 'other', 'infusable' => true ] ); @@ -969,11 +969,11 @@ class AbuseFilterViewEdit extends AbuseFilterView { $lang = $this->getLanguage(); foreach ( $res as $row ) { - if ( $lang->lcfirst( $row->page_title ) == $lang->lcfirst( $warnMsg ) ) { + if ( $lang->lcfirst( $row->page_title ) === $lang->lcfirst( $warnMsg ) ) { $existingSelector->setValue( $lang->lcfirst( $warnMsg ) ); } - if ( $row->page_title != "Abusefilter-$action" ) { + if ( $row->page_title !== "Abusefilter-$action" ) { $options += [ $lang->lcfirst( $row->page_title ) => $lang->lcfirst( $row->page_title ) ]; } } @@ -1051,7 +1051,7 @@ class AbuseFilterViewEdit extends AbuseFilterView { * or NULL if the filter does not exist. */ public function loadFilterData( $id ) { - if ( $id == 'new' ) { + if ( $id === 'new' ) { $obj = new stdClass; $obj->af_pattern = ''; $obj->af_enabled = 1; @@ -1195,7 +1195,7 @@ class AbuseFilterViewEdit extends AbuseFilterView { if ( $enabled ) { $parameters = []; - if ( $action == 'throttle' ) { + if ( $action === 'throttle' ) { // We need to load the parameters $throttleCount = $request->getIntOrNull( 'wpFilterThrottleCount' ); $throttlePeriod = $request->getIntOrNull( 'wpFilterThrottlePeriod' ); @@ -1215,28 +1215,28 @@ class AbuseFilterViewEdit extends AbuseFilterView { $parameters[0] = $this->mFilter; $parameters[1] = "$throttleCount,$throttlePeriod"; $parameters = array_merge( $parameters, $throttleGroups ); - } elseif ( $action == 'warn' ) { + } elseif ( $action === 'warn' ) { $specMsg = $request->getVal( 'wpFilterWarnMessage' ); - if ( $specMsg == 'other' ) { + if ( $specMsg === 'other' ) { $specMsg = $request->getVal( 'wpFilterWarnMessageOther' ); } $parameters[0] = $specMsg; - } elseif ( $action == 'block' ) { + } elseif ( $action === 'block' ) { $parameters[0] = $request->getCheck( 'wpFilterBlockTalk' ) ? 'blocktalk' : 'noTalkBlockSet'; $parameters[1] = $request->getVal( 'wpBlockAnonDuration' ); $parameters[2] = $request->getVal( 'wpBlockUserDuration' ); - } elseif ( $action == 'disallow' ) { + } elseif ( $action === 'disallow' ) { $specMsg = $request->getVal( 'wpFilterDisallowMessage' ); - if ( $specMsg == 'other' ) { + if ( $specMsg === 'other' ) { $specMsg = $request->getVal( 'wpFilterDisallowMessageOther' ); } $parameters[0] = $specMsg; - } elseif ( $action == 'tag' ) { + } elseif ( $action === 'tag' ) { $parameters = explode( ',', trim( $request->getText( 'wpFilterTags' ) ) ); } diff --git a/includes/Views/AbuseFilterViewExamine.php b/includes/Views/AbuseFilterViewExamine.php index 1dcba5eed..1c59a8e9e 100644 --- a/includes/Views/AbuseFilterViewExamine.php +++ b/includes/Views/AbuseFilterViewExamine.php @@ -18,7 +18,7 @@ class AbuseFilterViewExamine extends AbuseFilterView { if ( count( $this->mParams ) > 1 && is_numeric( $this->mParams[1] ) ) { $this->showExaminerForRC( $this->mParams[1] ); } elseif ( count( $this->mParams ) > 2 - && $this->mParams[1] == 'log' + && $this->mParams[1] === 'log' && is_numeric( $this->mParams[2] ) ) { $this->showExaminerForLogEntry( $this->mParams[2] ); diff --git a/includes/Views/AbuseFilterViewList.php b/includes/Views/AbuseFilterViewList.php index 966bfc299..579a85aad 100644 --- a/includes/Views/AbuseFilterViewList.php +++ b/includes/Views/AbuseFilterViewList.php @@ -48,7 +48,7 @@ class AbuseFilterViewList extends AbuseFilterView { $searchEnabled = $this->canViewPrivate() && !( $config->get( 'AbuseFilterCentralDB' ) !== null && !$config->get( 'AbuseFilterIsCentral' ) && - $scope == 'global' ); + $scope === 'global' ); if ( $searchEnabled ) { $querypattern = $request->getVal( 'querypattern' ); @@ -58,9 +58,9 @@ class AbuseFilterViewList extends AbuseFilterView { $searchmode = ''; } - if ( $deleted == 'show' ) { + if ( $deleted === 'show' ) { // Nothing - } elseif ( $deleted == 'only' ) { + } elseif ( $deleted === 'only' ) { $conds['af_deleted'] = 1; } else { // hide, or anything else. @@ -75,9 +75,9 @@ class AbuseFilterViewList extends AbuseFilterView { $conds['af_hidden'] = 0; } - if ( $scope == 'local' ) { + if ( $scope === 'local' ) { $conds['af_global'] = 0; - } elseif ( $scope == 'global' ) { + } elseif ( $scope === 'global' ) { $conds['af_global'] = 1; } @@ -163,7 +163,7 @@ class AbuseFilterViewList extends AbuseFilterView { if ( $config->get( 'AbuseFilterCentralDB' ) !== null && !$config->get( 'AbuseFilterIsCentral' ) - && $scope == 'global' + && $scope === 'global' ) { $pager = new GlobalAbuseFilterPager( $this, diff --git a/includes/Views/AbuseFilterViewRevert.php b/includes/Views/AbuseFilterViewRevert.php index 38a0d0731..d1264a835 100644 --- a/includes/Views/AbuseFilterViewRevert.php +++ b/includes/Views/AbuseFilterViewRevert.php @@ -259,7 +259,7 @@ class AbuseFilterViewRevert extends AbuseFilterView { switch ( $action ) { case 'block': $block = Block::newFromTarget( $result['user'] ); - if ( !( $block && $block->getBy() == AbuseFilter::getFilterUser()->getId() ) ) { + if ( !( $block && $block->getBy() === AbuseFilter::getFilterUser()->getId() ) ) { // Not blocked by abuse filter return false; } diff --git a/includes/Views/AbuseFilterViewTestBatch.php b/includes/Views/AbuseFilterViewTestBatch.php index 3a034cd1a..778bf89a8 100644 --- a/includes/Views/AbuseFilterViewTestBatch.php +++ b/includes/Views/AbuseFilterViewTestBatch.php @@ -164,7 +164,7 @@ class AbuseFilterViewTestBatch extends AbuseFilterView { $conds['rc_bot'] = 0; } - $action = $this->mTestAction != '0' ? $this->mTestAction : false; + $action = $this->mTestAction !== '0' ? $this->mTestAction : false; $conds[] = $this->buildTestConditions( $dbr, $action ); // Get our ChangesList diff --git a/includes/pagers/AbuseFilterHistoryPager.php b/includes/pagers/AbuseFilterHistoryPager.php index b4650b394..d9539a8ed 100644 --- a/includes/pagers/AbuseFilterHistoryPager.php +++ b/includes/pagers/AbuseFilterHistoryPager.php @@ -210,7 +210,7 @@ class AbuseFilterHistoryPager extends TablePager { $changed = explode( ',', $row->afh_changed_fields ); $fieldChanged = false; - if ( $field == 'afh_flags' ) { + if ( $field === 'afh_flags' ) { // The field is changed if any of these filters are in the $changed array. $filters = [ 'af_enabled', 'af_hidden', 'af_deleted', 'af_global' ]; if ( count( array_intersect( $filters, $changed ) ) ) { diff --git a/includes/parser/AFPData.php b/includes/parser/AFPData.php index f0f9c0f82..bd79225e7 100644 --- a/includes/parser/AFPData.php +++ b/includes/parser/AFPData.php @@ -78,21 +78,21 @@ class AFPData { * @return AFPData */ public static function castTypes( AFPData $orig, $target ) { - if ( $orig->type == $target ) { + if ( $orig->type === $target ) { return $orig->dup(); } - if ( $target == self::DNULL ) { + if ( $target === self::DNULL ) { return new AFPData(); } - if ( $orig->type == self::DARRAY ) { - if ( $target == self::DBOOL ) { + if ( $orig->type === self::DARRAY ) { + if ( $target === self::DBOOL ) { return new AFPData( self::DBOOL, (bool)count( $orig->data ) ); - } elseif ( $target == self::DFLOAT ) { + } elseif ( $target === self::DFLOAT ) { return new AFPData( self::DFLOAT, floatval( count( $orig->data ) ) ); - } elseif ( $target == self::DINT ) { + } elseif ( $target === self::DINT ) { return new AFPData( self::DINT, intval( count( $orig->data ) ) ); - } elseif ( $target == self::DSTRING ) { + } elseif ( $target === self::DSTRING ) { $s = ''; foreach ( $orig->data as $item ) { $s .= $item->toString() . "\n"; @@ -102,15 +102,15 @@ class AFPData { } } - if ( $target == self::DBOOL ) { + if ( $target === self::DBOOL ) { return new AFPData( self::DBOOL, (bool)$orig->data ); - } elseif ( $target == self::DFLOAT ) { + } elseif ( $target === self::DFLOAT ) { return new AFPData( self::DFLOAT, floatval( $orig->data ) ); - } elseif ( $target == self::DINT ) { + } elseif ( $target === self::DINT ) { return new AFPData( self::DINT, intval( $orig->data ) ); - } elseif ( $target == self::DSTRING ) { + } elseif ( $target === self::DSTRING ) { return new AFPData( self::DSTRING, strval( $orig->data ) ); - } elseif ( $target == self::DARRAY ) { + } elseif ( $target === self::DARRAY ) { return new AFPData( self::DARRAY, [ $orig ] ); } } @@ -146,7 +146,7 @@ class AFPData { $a = $a->toString(); $b = $b->toString(); - if ( $a == '' || $b == '' ) { + if ( $a === '' || $b === '' ) { return new AFPData( self::DBOOL, false ); } @@ -178,10 +178,10 @@ class AFPData { * @return bool */ private static function equals( AFPData $d1, AFPData $d2, $strict = false ) { - if ( $d1->type != self::DARRAY && $d2->type != self::DARRAY ) { - $typecheck = $d1->type == $d2->type || !$strict; + if ( $d1->type !== self::DARRAY && $d2->type !== self::DARRAY ) { + $typecheck = $d1->type === $d2->type || !$strict; return $typecheck && $d1->toString() === $d2->toString(); - } elseif ( $d1->type == self::DARRAY && $d2->type == self::DARRAY ) { + } elseif ( $d1->type === self::DARRAY && $d2->type === self::DARRAY ) { $data1 = $d1->data; $data2 = $d2->data; if ( count( $data1 ) !== count( $data2 ) ) { @@ -199,10 +199,10 @@ class AFPData { if ( $strict ) { return false; } - if ( $d1->type == self::DARRAY && count( $d1->data ) === 0 ) { - return ( $d2->type == self::DBOOL && $d2->toBool() == false ) || $d2->type == self::DNULL; - } elseif ( $d2->type == self::DARRAY && count( $d2->data ) === 0 ) { - return ( $d1->type == self::DBOOL && $d1->toBool() == false ) || $d1->type == self::DNULL; + if ( $d1->type === self::DARRAY && count( $d1->data ) === 0 ) { + return ( $d2->type === self::DBOOL && $d2->toBool() === false ) || $d2->type === self::DNULL; + } elseif ( $d2->type === self::DARRAY && count( $d2->data ) === 0 ) { + return ( $d1->type === self::DBOOL && $d1->toBool() === false ) || $d1->type === self::DNULL; } else { return false; } @@ -272,7 +272,7 @@ class AFPData { * @return AFPData */ public static function unaryMinus( AFPData $data ) { - if ( $data->type == self::DINT ) { + if ( $data->type === self::DINT ) { return new AFPData( $data->type, -$data->toInt() ); } else { return new AFPData( $data->type, -$data->toFloat() ); @@ -289,11 +289,11 @@ class AFPData { public static function boolOp( AFPData $a, AFPData $b, $op ) { $a = $a->toBool(); $b = $b->toBool(); - if ( $op == '|' ) { + if ( $op === '|' ) { return new AFPData( self::DBOOL, $a || $b ); - } elseif ( $op == '&' ) { + } elseif ( $op === '&' ) { return new AFPData( self::DBOOL, $a && $b ); - } elseif ( $op == '^' ) { + } elseif ( $op === '^' ) { return new AFPData( self::DBOOL, $a xor $b ); } // Should never happen. @@ -308,25 +308,25 @@ class AFPData { * @throws AFPException */ public static function compareOp( AFPData $a, AFPData $b, $op ) { - if ( $op == '==' || $op == '=' ) { + if ( $op === '==' || $op === '=' ) { return new AFPData( self::DBOOL, self::equals( $a, $b ) ); - } elseif ( $op == '!=' ) { + } elseif ( $op === '!=' ) { return new AFPData( self::DBOOL, !self::equals( $a, $b ) ); - } elseif ( $op == '===' ) { + } elseif ( $op === '===' ) { return new AFPData( self::DBOOL, self::equals( $a, $b, true ) ); - } elseif ( $op == '!==' ) { + } elseif ( $op === '!==' ) { return new AFPData( self::DBOOL, !self::equals( $a, $b, true ) ); } $a = $a->toString(); $b = $b->toString(); - if ( $op == '>' ) { + if ( $op === '>' ) { return new AFPData( self::DBOOL, $a > $b ); - } elseif ( $op == '<' ) { + } elseif ( $op === '<' ) { return new AFPData( self::DBOOL, $a < $b ); - } elseif ( $op == '>=' ) { + } elseif ( $op === '>=' ) { return new AFPData( self::DBOOL, $a >= $b ); - } elseif ( $op == '<=' ) { + } elseif ( $op === '<=' ) { return new AFPData( self::DBOOL, $a <= $b ); } // Should never happen @@ -346,15 +346,15 @@ class AFPData { $a = $a->toNumber(); $b = $b->toNumber(); - if ( $op != '*' && $b == 0 ) { + if ( $op !== '*' && $b === 0 ) { throw new AFPUserVisibleException( 'dividebyzero', $pos, [ $a ] ); } - if ( $op == '*' ) { + if ( $op === '*' ) { $data = $a * $b; - } elseif ( $op == '/' ) { + } elseif ( $op === '/' ) { $data = $a / $b; - } elseif ( $op == '%' ) { + } elseif ( $op === '%' ) { $data = $a % $b; } else { // Should never happen @@ -378,9 +378,9 @@ class AFPData { * @return AFPData */ public static function sum( AFPData $a, AFPData $b ) { - if ( $a->type == self::DSTRING || $b->type == self::DSTRING ) { + if ( $a->type === self::DSTRING || $b->type === self::DSTRING ) { return new AFPData( self::DSTRING, $a->toString() . $b->toString() ); - } elseif ( $a->type == self::DARRAY && $b->type == self::DARRAY ) { + } elseif ( $a->type === self::DARRAY && $b->type === self::DARRAY ) { return new AFPData( self::DARRAY, array_merge( $a->toArray(), $b->toArray() ) ); } else { $res = $a->toNumber() + $b->toNumber(); @@ -465,7 +465,7 @@ class AFPData { * @return int|float */ public function toNumber() { - return $this->type == self::DINT ? $this->toInt() : $this->toFloat(); + return $this->type === self::DINT ? $this->toInt() : $this->toFloat(); } /** diff --git a/includes/parser/AFPTreeNode.php b/includes/parser/AFPTreeNode.php index 1780b1858..2f6cac74b 100644 --- a/includes/parser/AFPTreeNode.php +++ b/includes/parser/AFPTreeNode.php @@ -108,7 +108,7 @@ class AFPTreeNode { } private function toDebugStringInner() { - if ( $this->type == self::ATOM ) { + if ( $this->type === self::ATOM ) { return [ "ATOM({$this->children->type} {$this->children->value})" ]; } diff --git a/includes/parser/AFPTreeParser.php b/includes/parser/AFPTreeParser.php index 4fa35356d..3b77cf544 100644 --- a/includes/parser/AFPTreeParser.php +++ b/includes/parser/AFPTreeParser.php @@ -86,7 +86,7 @@ class AFPTreeParser { protected function doLevelEntry() { $result = $this->doLevelSemicolon(); - if ( $this->mCur->type != AFPToken::TNONE ) { + if ( $this->mCur->type !== AFPToken::TNONE ) { throw new AFPUserVisibleException( 'unexpectedatend', $this->mPos, [ $this->mCur->type ] @@ -108,23 +108,23 @@ class AFPTreeParser { $this->move(); $position = $this->mPos; - if ( $this->mCur->type == AFPToken::TNONE ) { + if ( $this->mCur->type === AFPToken::TNONE ) { break; } // Allow empty statements. - if ( $this->mCur->type == AFPToken::TSTATEMENTSEPARATOR ) { + if ( $this->mCur->type === AFPToken::TSTATEMENTSEPARATOR ) { continue; } $statements[] = $this->doLevelSet(); $position = $this->mPos; - } while ( $this->mCur->type == AFPToken::TSTATEMENTSEPARATOR ); + } while ( $this->mCur->type === AFPToken::TSTATEMENTSEPARATOR ); // Flatten the tree if possible. - if ( count( $statements ) == 0 ) { + if ( count( $statements ) === 0 ) { return null; - } elseif ( count( $statements ) == 1 ) { + } elseif ( count( $statements ) === 1 ) { return $statements[0]; } else { return new AFPTreeNode( AFPTreeNode::SEMICOLON, $statements, $position ); @@ -138,7 +138,7 @@ class AFPTreeParser { * @throws AFPUserVisibleException */ protected function doLevelSet() { - if ( $this->mCur->type == AFPToken::TID ) { + if ( $this->mCur->type === AFPToken::TID ) { $varname = $this->mCur->value; // Speculatively parse the assignment statement assuming it can @@ -146,7 +146,7 @@ class AFPTreeParser { $initialState = $this->getState(); $this->move(); - if ( $this->mCur->type == AFPToken::TOP && $this->mCur->value == ':=' ) { + if ( $this->mCur->type === AFPToken::TOP && $this->mCur->value === ':=' ) { $position = $this->mPos; $this->move(); $value = $this->doLevelSet(); @@ -154,24 +154,24 @@ class AFPTreeParser { return new AFPTreeNode( AFPTreeNode::ASSIGNMENT, [ $varname, $value ], $position ); } - if ( $this->mCur->type == AFPToken::TSQUAREBRACKET && $this->mCur->value == '[' ) { + if ( $this->mCur->type === AFPToken::TSQUAREBRACKET && $this->mCur->value === '[' ) { $this->move(); - if ( $this->mCur->type == AFPToken::TSQUAREBRACKET && $this->mCur->value == ']' ) { + if ( $this->mCur->type === AFPToken::TSQUAREBRACKET && $this->mCur->value === ']' ) { $index = 'append'; } else { // Parse index offset. $this->setState( $initialState ); $this->move(); $index = $this->doLevelSemicolon(); - if ( !( $this->mCur->type == AFPToken::TSQUAREBRACKET && $this->mCur->value == ']' ) ) { + if ( !( $this->mCur->type === AFPToken::TSQUAREBRACKET && $this->mCur->value === ']' ) ) { throw new AFPUserVisibleException( 'expectednotfound', $this->mPos, [ ']', $this->mCur->type, $this->mCur->value ] ); } } $this->move(); - if ( $this->mCur->type == AFPToken::TOP && $this->mCur->value == ':=' ) { + if ( $this->mCur->type === AFPToken::TOP && $this->mCur->value === ':=' ) { $position = $this->mPos; $this->move(); $value = $this->doLevelSet(); @@ -203,12 +203,12 @@ class AFPTreeParser { * @throws AFPUserVisibleException */ protected function doLevelConditions() { - if ( $this->mCur->type == AFPToken::TKEYWORD && $this->mCur->value == 'if' ) { + if ( $this->mCur->type === AFPToken::TKEYWORD && $this->mCur->value === 'if' ) { $position = $this->mPos; $this->move(); $condition = $this->doLevelBoolOps(); - if ( !( $this->mCur->type == AFPToken::TKEYWORD && $this->mCur->value == 'then' ) ) { + if ( !( $this->mCur->type === AFPToken::TKEYWORD && $this->mCur->value === 'then' ) ) { throw new AFPUserVisibleException( 'expectednotfound', $this->mPos, [ @@ -222,7 +222,7 @@ class AFPTreeParser { $valueIfTrue = $this->doLevelConditions(); - if ( !( $this->mCur->type == AFPToken::TKEYWORD && $this->mCur->value == 'else' ) ) { + if ( !( $this->mCur->type === AFPToken::TKEYWORD && $this->mCur->value === 'else' ) ) { throw new AFPUserVisibleException( 'expectednotfound', $this->mPos, [ @@ -236,7 +236,7 @@ class AFPTreeParser { $valueIfFalse = $this->doLevelConditions(); - if ( !( $this->mCur->type == AFPToken::TKEYWORD && $this->mCur->value == 'end' ) ) { + if ( !( $this->mCur->type === AFPToken::TKEYWORD && $this->mCur->value === 'end' ) ) { throw new AFPUserVisibleException( 'expectednotfound', $this->mPos, [ @@ -256,12 +256,12 @@ class AFPTreeParser { } $condition = $this->doLevelBoolOps(); - if ( $this->mCur->type == AFPToken::TOP && $this->mCur->value == '?' ) { + if ( $this->mCur->type === AFPToken::TOP && $this->mCur->value === '?' ) { $position = $this->mPos; $this->move(); $valueIfTrue = $this->doLevelConditions(); - if ( !( $this->mCur->type == AFPToken::TOP && $this->mCur->value == ':' ) ) { + if ( !( $this->mCur->type === AFPToken::TOP && $this->mCur->value === ':' ) ) { throw new AFPUserVisibleException( 'expectednotfound', $this->mPos, [ @@ -292,7 +292,7 @@ class AFPTreeParser { protected function doLevelBoolOps() { $leftOperand = $this->doLevelCompares(); $ops = [ '&', '|', '^' ]; - while ( $this->mCur->type == AFPToken::TOP && in_array( $this->mCur->value, $ops ) ) { + while ( $this->mCur->type === AFPToken::TOP && in_array( $this->mCur->value, $ops ) ) { $op = $this->mCur->value; $position = $this->mPos; $this->move(); @@ -316,7 +316,7 @@ class AFPTreeParser { protected function doLevelCompares() { $leftOperand = $this->doLevelSumRels(); $ops = [ '==', '===', '!=', '!==', '<', '>', '<=', '>=', '=' ]; - while ( $this->mCur->type == AFPToken::TOP && in_array( $this->mCur->value, $ops ) ) { + while ( $this->mCur->type === AFPToken::TOP && in_array( $this->mCur->value, $ops ) ) { $op = $this->mCur->value; $position = $this->mPos; $this->move(); @@ -338,7 +338,7 @@ class AFPTreeParser { protected function doLevelSumRels() { $leftOperand = $this->doLevelMulRels(); $ops = [ '+', '-' ]; - while ( $this->mCur->type == AFPToken::TOP && in_array( $this->mCur->value, $ops ) ) { + while ( $this->mCur->type === AFPToken::TOP && in_array( $this->mCur->value, $ops ) ) { $op = $this->mCur->value; $position = $this->mPos; $this->move(); @@ -360,7 +360,7 @@ class AFPTreeParser { protected function doLevelMulRels() { $leftOperand = $this->doLevelPow(); $ops = [ '*', '/', '%' ]; - while ( $this->mCur->type == AFPToken::TOP && in_array( $this->mCur->value, $ops ) ) { + while ( $this->mCur->type === AFPToken::TOP && in_array( $this->mCur->value, $ops ) ) { $op = $this->mCur->value; $position = $this->mPos; $this->move(); @@ -381,7 +381,7 @@ class AFPTreeParser { */ protected function doLevelPow() { $base = $this->doLevelBoolInvert(); - while ( $this->mCur->type == AFPToken::TOP && $this->mCur->value == '**' ) { + while ( $this->mCur->type === AFPToken::TOP && $this->mCur->value === '**' ) { $position = $this->mPos; $this->move(); $exponent = $this->doLevelBoolInvert(); @@ -396,7 +396,7 @@ class AFPTreeParser { * @return AFPTreeNode */ protected function doLevelBoolInvert() { - if ( $this->mCur->type == AFPToken::TOP && $this->mCur->value == '!' ) { + if ( $this->mCur->type === AFPToken::TOP && $this->mCur->value === '!' ) { $position = $this->mPos; $this->move(); $argument = $this->doLevelKeywordOperators(); @@ -414,7 +414,7 @@ class AFPTreeParser { protected function doLevelKeywordOperators() { $leftOperand = $this->doLevelUnarys(); $keyword = strtolower( $this->mCur->value ); - if ( $this->mCur->type == AFPToken::TKEYWORD && + if ( $this->mCur->type === AFPToken::TKEYWORD && isset( AbuseFilterParser::$mKeywords[$keyword] ) ) { $position = $this->mPos; @@ -438,7 +438,7 @@ class AFPTreeParser { */ protected function doLevelUnarys() { $op = $this->mCur->value; - if ( $this->mCur->type == AFPToken::TOP && ( $op == "+" || $op == "-" ) ) { + if ( $this->mCur->type === AFPToken::TOP && ( $op === "+" || $op === "-" ) ) { $position = $this->mPos; $this->move(); $argument = $this->doLevelArrayElements(); @@ -455,12 +455,12 @@ class AFPTreeParser { */ protected function doLevelArrayElements() { $array = $this->doLevelParenthesis(); - while ( $this->mCur->type == AFPToken::TSQUAREBRACKET && $this->mCur->value == '[' ) { + while ( $this->mCur->type === AFPToken::TSQUAREBRACKET && $this->mCur->value === '[' ) { $position = $this->mPos; $index = $this->doLevelSemicolon(); $array = new AFPTreeNode( AFPTreeNode::ARRAY_INDEX, [ $array, $index ], $position ); - if ( !( $this->mCur->type == AFPToken::TSQUAREBRACKET && $this->mCur->value == ']' ) ) { + if ( !( $this->mCur->type === AFPToken::TSQUAREBRACKET && $this->mCur->value === ']' ) ) { throw new AFPUserVisibleException( 'expectednotfound', $this->mPos, [ ']', $this->mCur->type, $this->mCur->value ] ); } @@ -477,10 +477,10 @@ class AFPTreeParser { * @throws AFPUserVisibleException */ protected function doLevelParenthesis() { - if ( $this->mCur->type == AFPToken::TBRACE && $this->mCur->value == '(' ) { + if ( $this->mCur->type === AFPToken::TBRACE && $this->mCur->value === '(' ) { $result = $this->doLevelSemicolon(); - if ( !( $this->mCur->type == AFPToken::TBRACE && $this->mCur->value == ')' ) ) { + if ( !( $this->mCur->type === AFPToken::TBRACE && $this->mCur->value === ')' ) ) { throw new AFPUserVisibleException( 'expectednotfound', $this->mPos, @@ -502,13 +502,13 @@ class AFPTreeParser { * @throws AFPUserVisibleException */ protected function doLevelFunction() { - if ( $this->mCur->type == AFPToken::TID && + if ( $this->mCur->type === AFPToken::TID && isset( AbuseFilterParser::$mFunctions[$this->mCur->value] ) ) { $func = $this->mCur->value; $position = $this->mPos; $this->move(); - if ( $this->mCur->type != AFPToken::TBRACE || $this->mCur->value != '(' ) { + if ( $this->mCur->type !== AFPToken::TBRACE || $this->mCur->value !== '(' ) { throw new AFPUserVisibleException( 'expectednotfound', $this->mPos, [ @@ -522,9 +522,9 @@ class AFPTreeParser { $args = []; do { $args[] = $this->doLevelSemicolon(); - } while ( $this->mCur->type == AFPToken::TCOMMA ); + } while ( $this->mCur->type === AFPToken::TCOMMA ); - if ( $this->mCur->type != AFPToken::TBRACE || $this->mCur->value != ')' ) { + if ( $this->mCur->type !== AFPToken::TBRACE || $this->mCur->value !== ')' ) { throw new AFPUserVisibleException( 'expectednotfound', $this->mPos, [ @@ -570,20 +570,20 @@ class AFPTreeParser { ); /** @noinspection PhpMissingBreakStatementInspection */ case AFPToken::TSQUAREBRACKET: - if ( $this->mCur->value == '[' ) { + if ( $this->mCur->value === '[' ) { $array = []; while ( true ) { $this->move(); - if ( $this->mCur->type == AFPToken::TSQUAREBRACKET && $this->mCur->value == ']' ) { + if ( $this->mCur->type === AFPToken::TSQUAREBRACKET && $this->mCur->value === ']' ) { break; } $array[] = $this->doLevelSet(); - if ( $this->mCur->type == AFPToken::TSQUAREBRACKET && $this->mCur->value == ']' ) { + if ( $this->mCur->type === AFPToken::TSQUAREBRACKET && $this->mCur->value === ']' ) { break; } - if ( $this->mCur->type != AFPToken::TCOMMA ) { + if ( $this->mCur->type !== AFPToken::TCOMMA ) { throw new AFPUserVisibleException( 'expectednotfound', $this->mPos, diff --git a/includes/parser/AbuseFilterCachingParser.php b/includes/parser/AbuseFilterCachingParser.php index 3f62a411d..de8aa387d 100644 --- a/includes/parser/AbuseFilterCachingParser.php +++ b/includes/parser/AbuseFilterCachingParser.php @@ -142,7 +142,7 @@ class AbuseFilterCachingParser extends AbuseFilterParser { list( $array, $offset ) = $node->children; $array = $this->evalNode( $array ); - if ( $array->type != AFPData::DARRAY ) { + if ( $array->type !== AFPData::DARRAY ) { throw new AFPUserVisibleException( 'notarray', $node->position, [] ); } @@ -159,7 +159,7 @@ class AbuseFilterCachingParser extends AbuseFilterParser { case AFPTreeNode::UNARY: list( $operation, $argument ) = $node->children; $argument = $this->evalNode( $argument ); - if ( $operation == '-' ) { + if ( $operation === '-' ) { return AFPData::unaryMinus( $argument ); } return $argument; @@ -218,7 +218,7 @@ class AbuseFilterCachingParser extends AbuseFilterParser { $leftOperand = $this->evalNode( $leftOperand ); $value = $leftOperand->toBool(); // Short-circuit. - if ( ( !$value && $op == '&' ) || ( $value && $op == '|' ) ) { + if ( ( !$value && $op === '&' ) || ( $value && $op === '|' ) ) { return $leftOperand; } $rightOperand = $this->evalNode( $rightOperand ); @@ -243,7 +243,7 @@ class AbuseFilterCachingParser extends AbuseFilterParser { list( $varName, $offset, $value ) = $node->children; $array = $this->mVars->getVar( $varName ); - if ( $array->type != AFPData::DARRAY ) { + if ( $array->type !== AFPData::DARRAY ) { throw new AFPUserVisibleException( 'notarray', $node->position, [] ); } @@ -263,7 +263,7 @@ class AbuseFilterCachingParser extends AbuseFilterParser { list( $varName, $value ) = $node->children; $array = $this->mVars->getVar( $varName ); - if ( $array->type != AFPData::DARRAY ) { + if ( $array->type !== AFPData::DARRAY ) { throw new AFPUserVisibleException( 'notarray', $node->position, [] ); } diff --git a/includes/parser/AbuseFilterParser.php b/includes/parser/AbuseFilterParser.php index 6677a61c8..543aaf33b 100644 --- a/includes/parser/AbuseFilterParser.php +++ b/includes/parser/AbuseFilterParser.php @@ -142,17 +142,17 @@ class AbuseFilterParser { */ protected function skipOverBraces() { $braces = 1; - while ( $this->mCur->type != AFPToken::TNONE && $braces > 0 ) { + while ( $this->mCur->type !== AFPToken::TNONE && $braces > 0 ) { $this->move(); - if ( $this->mCur->type == AFPToken::TBRACE ) { - if ( $this->mCur->value == '(' ) { + if ( $this->mCur->type === AFPToken::TBRACE ) { + if ( $this->mCur->value === '(' ) { $braces++; - } elseif ( $this->mCur->value == ')' ) { + } elseif ( $this->mCur->value === ')' ) { $braces--; } } } - if ( !( $this->mCur->type == AFPToken::TBRACE && $this->mCur->value == ')' ) ) { + if ( !( $this->mCur->type === AFPToken::TBRACE && $this->mCur->value === ')' ) ) { throw new AFPUserVisibleException( 'expectednotfound', $this->mCur->pos, [ ')' ] ); } } @@ -200,7 +200,7 @@ class AbuseFilterParser { protected function doLevelEntry( &$result ) { $this->doLevelSemicolon( $result ); - if ( $this->mCur->type != AFPToken::TNONE ) { + if ( $this->mCur->type !== AFPToken::TNONE ) { throw new AFPUserVisibleException( 'unexpectedatend', $this->mCur->pos, [ $this->mCur->type ] @@ -216,10 +216,10 @@ class AbuseFilterParser { protected function doLevelSemicolon( &$result ) { do { $this->move(); - if ( $this->mCur->type != AFPToken::TSTATEMENTSEPARATOR ) { + if ( $this->mCur->type !== AFPToken::TSTATEMENTSEPARATOR ) { $this->doLevelSet( $result ); } - } while ( $this->mCur->type == AFPToken::TSTATEMENTSEPARATOR ); + } while ( $this->mCur->type === AFPToken::TSTATEMENTSEPARATOR ); } /** @@ -229,18 +229,18 @@ class AbuseFilterParser { * @throws AFPUserVisibleException */ protected function doLevelSet( &$result ) { - if ( $this->mCur->type == AFPToken::TID ) { + if ( $this->mCur->type === AFPToken::TID ) { $varname = $this->mCur->value; $prev = $this->getState(); $this->move(); - if ( $this->mCur->type == AFPToken::TOP && $this->mCur->value == ':=' ) { + if ( $this->mCur->type === AFPToken::TOP && $this->mCur->value === ':=' ) { $this->move(); $this->doLevelSet( $result ); $this->setUserVariable( $varname, $result ); return; - } elseif ( $this->mCur->type == AFPToken::TSQUAREBRACKET && $this->mCur->value == '[' ) { + } elseif ( $this->mCur->type === AFPToken::TSQUAREBRACKET && $this->mCur->value === '[' ) { if ( !$this->mVars->varIsSet( $varname ) ) { throw new AFPUserVisibleException( 'unrecognisedvar', $this->mCur->pos, @@ -248,12 +248,12 @@ class AbuseFilterParser { ); } $array = $this->mVars->getVar( $varname ); - if ( $array->type != AFPData::DARRAY ) { + if ( $array->type !== AFPData::DARRAY ) { throw new AFPUserVisibleException( 'notarray', $this->mCur->pos, [] ); } $array = $array->toArray(); $this->move(); - if ( $this->mCur->type == AFPToken::TSQUAREBRACKET && $this->mCur->value == ']' ) { + if ( $this->mCur->type === AFPToken::TSQUAREBRACKET && $this->mCur->value === ']' ) { $idx = 'new'; } else { $this->setState( $prev ); @@ -261,7 +261,7 @@ class AbuseFilterParser { $idx = new AFPData(); $this->doLevelSemicolon( $idx ); $idx = $idx->toInt(); - if ( !( $this->mCur->type == AFPToken::TSQUAREBRACKET && $this->mCur->value == ']' ) ) { + if ( !( $this->mCur->type === AFPToken::TSQUAREBRACKET && $this->mCur->value === ']' ) ) { throw new AFPUserVisibleException( 'expectednotfound', $this->mCur->pos, [ ']', $this->mCur->type, $this->mCur->value ] ); } @@ -271,7 +271,7 @@ class AbuseFilterParser { } } $this->move(); - if ( $this->mCur->type == AFPToken::TOP && $this->mCur->value == ':=' ) { + if ( $this->mCur->type === AFPToken::TOP && $this->mCur->value === ':=' ) { $this->move(); $this->doLevelSet( $result ); if ( $idx === 'new' ) { @@ -299,11 +299,11 @@ class AbuseFilterParser { * @throws AFPUserVisibleException */ protected function doLevelConditions( &$result ) { - if ( $this->mCur->type == AFPToken::TKEYWORD && $this->mCur->value == 'if' ) { + if ( $this->mCur->type === AFPToken::TKEYWORD && $this->mCur->value === 'if' ) { $this->move(); $this->doLevelBoolOps( $result ); - if ( !( $this->mCur->type == AFPToken::TKEYWORD && $this->mCur->value == 'then' ) ) { + if ( !( $this->mCur->type === AFPToken::TKEYWORD && $this->mCur->value === 'then' ) ) { throw new AFPUserVisibleException( 'expectednotfound', $this->mCur->pos, [ @@ -329,7 +329,7 @@ class AbuseFilterParser { $this->mShortCircuit = $scOrig; } - if ( !( $this->mCur->type == AFPToken::TKEYWORD && $this->mCur->value == 'else' ) ) { + if ( !( $this->mCur->type === AFPToken::TKEYWORD && $this->mCur->value === 'else' ) ) { throw new AFPUserVisibleException( 'expectednotfound', $this->mCur->pos, [ @@ -350,7 +350,7 @@ class AbuseFilterParser { $this->mShortCircuit = $scOrig; } - if ( !( $this->mCur->type == AFPToken::TKEYWORD && $this->mCur->value == 'end' ) ) { + if ( !( $this->mCur->type === AFPToken::TKEYWORD && $this->mCur->value === 'end' ) ) { throw new AFPUserVisibleException( 'expectednotfound', $this->mCur->pos, [ @@ -369,7 +369,7 @@ class AbuseFilterParser { } } else { $this->doLevelBoolOps( $result ); - if ( $this->mCur->type == AFPToken::TOP && $this->mCur->value == '?' ) { + if ( $this->mCur->type === AFPToken::TOP && $this->mCur->value === '?' ) { $this->move(); $r1 = new AFPData(); $r2 = new AFPData(); @@ -385,7 +385,7 @@ class AbuseFilterParser { $this->mShortCircuit = $scOrig; } - if ( !( $this->mCur->type == AFPToken::TOP && $this->mCur->value == ':' ) ) { + if ( !( $this->mCur->type === AFPToken::TOP && $this->mCur->value === ':' ) ) { throw new AFPUserVisibleException( 'expectednotfound', $this->mCur->pos, [ @@ -423,13 +423,13 @@ class AbuseFilterParser { protected function doLevelBoolOps( &$result ) { $this->doLevelCompares( $result ); $ops = [ '&', '|', '^' ]; - while ( $this->mCur->type == AFPToken::TOP && in_array( $this->mCur->value, $ops ) ) { + while ( $this->mCur->type === AFPToken::TOP && in_array( $this->mCur->value, $ops ) ) { $op = $this->mCur->value; $this->move(); $r2 = new AFPData(); // We can go on quickly as either one statement with | is true or one with & is false - if ( ( $op == '&' && !$result->toBool() ) || ( $op == '|' && $result->toBool() ) ) { + if ( ( $op === '&' && !$result->toBool() ) || ( $op === '|' && $result->toBool() ) ) { $orig = $this->mShortCircuit; $this->mShortCircuit = $this->mAllowShort; $this->doLevelCompares( $r2 ); @@ -452,7 +452,7 @@ class AbuseFilterParser { protected function doLevelCompares( &$result ) { $this->doLevelSumRels( $result ); $ops = [ '==', '===', '!=', '!==', '<', '>', '<=', '>=', '=' ]; - while ( $this->mCur->type == AFPToken::TOP && in_array( $this->mCur->value, $ops ) ) { + while ( $this->mCur->type === AFPToken::TOP && in_array( $this->mCur->value, $ops ) ) { $op = $this->mCur->value; $this->move(); $r2 = new AFPData(); @@ -474,7 +474,7 @@ class AbuseFilterParser { protected function doLevelSumRels( &$result ) { $this->doLevelMulRels( $result ); $ops = [ '+', '-' ]; - while ( $this->mCur->type == AFPToken::TOP && in_array( $this->mCur->value, $ops ) ) { + while ( $this->mCur->type === AFPToken::TOP && in_array( $this->mCur->value, $ops ) ) { $op = $this->mCur->value; $this->move(); $r2 = new AFPData(); @@ -483,10 +483,10 @@ class AbuseFilterParser { // The result doesn't matter. continue; } - if ( $op == '+' ) { + if ( $op === '+' ) { $result = AFPData::sum( $result, $r2 ); } - if ( $op == '-' ) { + if ( $op === '-' ) { $result = AFPData::sub( $result, $r2 ); } } @@ -500,7 +500,7 @@ class AbuseFilterParser { protected function doLevelMulRels( &$result ) { $this->doLevelPow( $result ); $ops = [ '*', '/', '%' ]; - while ( $this->mCur->type == AFPToken::TOP && in_array( $this->mCur->value, $ops ) ) { + while ( $this->mCur->type === AFPToken::TOP && in_array( $this->mCur->value, $ops ) ) { $op = $this->mCur->value; $this->move(); $r2 = new AFPData(); @@ -520,7 +520,7 @@ class AbuseFilterParser { */ protected function doLevelPow( &$result ) { $this->doLevelBoolInvert( $result ); - while ( $this->mCur->type == AFPToken::TOP && $this->mCur->value == '**' ) { + while ( $this->mCur->type === AFPToken::TOP && $this->mCur->value === '**' ) { $this->move(); $expanent = new AFPData(); $this->doLevelBoolInvert( $expanent ); @@ -538,7 +538,7 @@ class AbuseFilterParser { * @param AFPData &$result */ protected function doLevelBoolInvert( &$result ) { - if ( $this->mCur->type == AFPToken::TOP && $this->mCur->value == '!' ) { + if ( $this->mCur->type === AFPToken::TOP && $this->mCur->value === '!' ) { $this->move(); $this->doLevelSpecialWords( $result ); if ( $this->mShortCircuit ) { @@ -559,7 +559,7 @@ class AbuseFilterParser { protected function doLevelSpecialWords( &$result ) { $this->doLevelUnarys( $result ); $keyword = strtolower( $this->mCur->value ); - if ( $this->mCur->type == AFPToken::TKEYWORD + if ( $this->mCur->type === AFPToken::TKEYWORD && isset( self::$mKeywords[$keyword] ) ) { $func = self::$mKeywords[$keyword]; @@ -585,14 +585,14 @@ class AbuseFilterParser { */ protected function doLevelUnarys( &$result ) { $op = $this->mCur->value; - if ( $this->mCur->type == AFPToken::TOP && ( $op == "+" || $op == "-" ) ) { + if ( $this->mCur->type === AFPToken::TOP && ( $op === "+" || $op === "-" ) ) { $this->move(); $this->doLevelArrayElements( $result ); if ( $this->mShortCircuit ) { // The result doesn't matter. return; } - if ( $op == '-' ) { + if ( $op === '-' ) { $result = AFPData::unaryMinus( $result ); } } else { @@ -608,15 +608,15 @@ class AbuseFilterParser { */ protected function doLevelArrayElements( &$result ) { $this->doLevelBraces( $result ); - while ( $this->mCur->type == AFPToken::TSQUAREBRACKET && $this->mCur->value == '[' ) { + while ( $this->mCur->type === AFPToken::TSQUAREBRACKET && $this->mCur->value === '[' ) { $idx = new AFPData(); $this->doLevelSemicolon( $idx ); - if ( !( $this->mCur->type == AFPToken::TSQUAREBRACKET && $this->mCur->value == ']' ) ) { + if ( !( $this->mCur->type === AFPToken::TSQUAREBRACKET && $this->mCur->value === ']' ) ) { throw new AFPUserVisibleException( 'expectednotfound', $this->mCur->pos, [ ']', $this->mCur->type, $this->mCur->value ] ); } $idx = $idx->toInt(); - if ( $result->type == AFPData::DARRAY ) { + if ( $result->type === AFPData::DARRAY ) { if ( count( $result->data ) <= $idx ) { throw new AFPUserVisibleException( 'outofbounds', $this->mCur->pos, [ $idx, count( $result->data ) ] ); @@ -636,13 +636,13 @@ class AbuseFilterParser { * @throws AFPUserVisibleException */ protected function doLevelBraces( &$result ) { - if ( $this->mCur->type == AFPToken::TBRACE && $this->mCur->value == '(' ) { + if ( $this->mCur->type === AFPToken::TBRACE && $this->mCur->value === '(' ) { if ( $this->mShortCircuit ) { $this->skipOverBraces(); } else { $this->doLevelSemicolon( $result ); } - if ( !( $this->mCur->type == AFPToken::TBRACE && $this->mCur->value == ')' ) ) { + if ( !( $this->mCur->type === AFPToken::TBRACE && $this->mCur->value === ')' ) ) { throw new AFPUserVisibleException( 'expectednotfound', $this->mCur->pos, @@ -662,10 +662,10 @@ class AbuseFilterParser { * @throws AFPUserVisibleException */ protected function doLevelFunction( &$result ) { - if ( $this->mCur->type == AFPToken::TID && isset( self::$mFunctions[$this->mCur->value] ) ) { + if ( $this->mCur->type === AFPToken::TID && isset( self::$mFunctions[$this->mCur->value] ) ) { $func = self::$mFunctions[$this->mCur->value]; $this->move(); - if ( $this->mCur->type != AFPToken::TBRACE || $this->mCur->value != '(' ) { + if ( $this->mCur->type !== AFPToken::TBRACE || $this->mCur->value !== '(' ) { throw new AFPUserVisibleException( 'expectednotfound', $this->mCur->pos, [ @@ -687,16 +687,16 @@ class AbuseFilterParser { $args = []; $state = $this->getState(); $this->move(); - if ( $this->mCur->type != AFPToken::TBRACE || $this->mCur->value != ')' ) { + if ( $this->mCur->type !== AFPToken::TBRACE || $this->mCur->value !== ')' ) { $this->setState( $state ); do { $r = new AFPData(); $this->doLevelSemicolon( $r ); $args[] = $r; - } while ( $this->mCur->type == AFPToken::TCOMMA ); + } while ( $this->mCur->type === AFPToken::TCOMMA ); } - if ( $this->mCur->type != AFPToken::TBRACE || $this->mCur->value != ')' ) { + if ( $this->mCur->type !== AFPToken::TBRACE || $this->mCur->value !== ')' ) { throw new AFPUserVisibleException( 'expectednotfound', $this->mCur->pos, [ @@ -763,11 +763,11 @@ class AbuseFilterParser { $result = new AFPData( AFPData::DINT, $tok ); break; case AFPToken::TKEYWORD: - if ( $tok == "true" ) { + if ( $tok === "true" ) { $result = new AFPData( AFPData::DBOOL, true ); - } elseif ( $tok == "false" ) { + } elseif ( $tok === "false" ) { $result = new AFPData( AFPData::DBOOL, false ); - } elseif ( $tok == "null" ) { + } elseif ( $tok === "null" ) { $result = new AFPData(); } else { throw new AFPUserVisibleException( @@ -781,25 +781,25 @@ class AbuseFilterParser { // Handled at entry level return; case AFPToken::TBRACE: - if ( $this->mCur->value == ')' ) { + if ( $this->mCur->value === ')' ) { // Handled at the entry level return; } case AFPToken::TSQUAREBRACKET: - if ( $this->mCur->value == '[' ) { + if ( $this->mCur->value === '[' ) { $array = []; while ( true ) { $this->move(); - if ( $this->mCur->type == AFPToken::TSQUAREBRACKET && $this->mCur->value == ']' ) { + if ( $this->mCur->type === AFPToken::TSQUAREBRACKET && $this->mCur->value === ']' ) { break; } $item = new AFPData(); $this->doLevelSet( $item ); $array[] = $item; - if ( $this->mCur->type == AFPToken::TSQUAREBRACKET && $this->mCur->value == ']' ) { + if ( $this->mCur->type === AFPToken::TSQUAREBRACKET && $this->mCur->value === ']' ) { break; } - if ( $this->mCur->type != AFPToken::TCOMMA ) { + if ( $this->mCur->type !== AFPToken::TCOMMA ) { throw new AFPUserVisibleException( 'expectednotfound', $this->mCur->pos, @@ -926,7 +926,7 @@ class AbuseFilterParser { protected function funcLen( $args ) { $this->checkEnoughArguments( $args, 'len', 1 ); - if ( $args[0]->type == AFPData::DARRAY ) { + if ( $args[0]->type === AFPData::DARRAY ) { // Don't use toString on arrays, but count $val = count( $args[0]->data ); } else { @@ -962,11 +962,11 @@ class AbuseFilterParser { protected function funcCount( $args ) { $this->checkEnoughArguments( $args, 'count', 1 ); - if ( $args[0]->type == AFPData::DARRAY && count( $args ) == 1 ) { + if ( $args[0]->type === AFPData::DARRAY && count( $args ) === 1 ) { return new AFPData( AFPData::DINT, count( $args[0]->data ) ); } - if ( count( $args ) == 1 ) { + if ( count( $args ) === 1 ) { $count = count( explode( ',', $args[0]->toString() ) ); } else { $needle = $args[0]->toString(); @@ -991,7 +991,7 @@ class AbuseFilterParser { protected function funcRCount( $args ) { $this->checkEnoughArguments( $args, 'rcount', 1 ); - if ( count( $args ) == 1 ) { + if ( count( $args ) === 1 ) { $count = count( explode( ',', $args[0]->toString() ) ); } else { $needle = $args[0]->toString(); diff --git a/includes/parser/AbuseFilterTokenizer.php b/includes/parser/AbuseFilterTokenizer.php index f4ec64c12..0833745e2 100644 --- a/includes/parser/AbuseFilterTokenizer.php +++ b/includes/parser/AbuseFilterTokenizer.php @@ -223,7 +223,7 @@ class AbuseFilterTokenizer { if ( $addLength ) { $token .= substr( $code, $offset, $addLength ); $offset += $addLength; - } elseif ( $code[$offset] == '\\' ) { + } elseif ( $code[$offset] === '\\' ) { switch ( $code[$offset + 1] ) { case '\\': $token .= '\\'; diff --git a/includes/special/SpecialAbuseFilter.php b/includes/special/SpecialAbuseFilter.php index ccd2f8eed..612f9c401 100644 --- a/includes/special/SpecialAbuseFilter.php +++ b/includes/special/SpecialAbuseFilter.php @@ -31,7 +31,7 @@ class SpecialAbuseFilter extends SpecialPage { $this->checkPermissions(); - if ( $request->getVal( 'result' ) == 'success' ) { + if ( $request->getVal( 'result' ) === 'success' ) { $out->setSubtitle( $this->msg( 'abusefilter-edit-done-subtitle' ) ); $changedFilter = intval( $request->getVal( 'changedfilter' ) ); $changeId = intval( $request->getVal( 'changeid' ) ); @@ -58,57 +58,57 @@ class SpecialAbuseFilter extends SpecialPage { } $params = array_values( $params ); - if ( $subpage == 'tools' ) { + if ( $subpage === 'tools' ) { $view = 'AbuseFilterViewTools'; $pageType = 'tools'; $out->addHelpLink( 'Extension:AbuseFilter/Rules format' ); } - if ( count( $params ) == 2 && $params[0] == 'revert' && is_numeric( $params[1] ) ) { + if ( count( $params ) === 2 && $params[0] === 'revert' && is_numeric( $params[1] ) ) { $this->mFilter = $params[1]; $view = 'AbuseFilterViewRevert'; $pageType = 'revert'; } - if ( count( $params ) && $params[0] == 'test' ) { + if ( count( $params ) && $params[0] === 'test' ) { $view = 'AbuseFilterViewTestBatch'; $pageType = 'test'; $out->addHelpLink( 'Extension:AbuseFilter/Rules format' ); } - if ( count( $params ) && $params[0] == 'examine' ) { + if ( count( $params ) && $params[0] === 'examine' ) { $view = 'AbuseFilterViewExamine'; $pageType = 'examine'; $out->addHelpLink( 'Extension:AbuseFilter/Rules format' ); } - if ( !empty( $params[0] ) && ( $params[0] == 'history' || $params[0] == 'log' ) ) { + if ( !empty( $params[0] ) && ( $params[0] === 'history' || $params[0] === 'log' ) ) { $pageType = ''; - if ( count( $params ) == 1 ) { + if ( count( $params ) === 1 ) { $view = 'AbuseFilterViewHistory'; $pageType = 'recentchanges'; - } elseif ( count( $params ) == 2 ) { + } elseif ( count( $params ) === 2 ) { // Second param is a filter ID $view = 'AbuseFilterViewHistory'; $pageType = 'recentchanges'; $this->mFilter = $params[1]; - } elseif ( count( $params ) == 4 && $params[2] == 'item' ) { + } elseif ( count( $params ) === 4 && $params[2] === 'item' ) { $this->mFilter = $params[1]; $this->mHistoryID = $params[3]; $view = 'AbuseFilterViewEdit'; - } elseif ( count( $params ) == 5 && $params[2] == 'diff' ) { + } elseif ( count( $params ) === 5 && $params[2] === 'diff' ) { // Special:AbuseFilter/history//diff// $view = 'AbuseFilterViewDiff'; } } - if ( is_numeric( $subpage ) || $subpage == 'new' ) { + if ( is_numeric( $subpage ) || $subpage === 'new' ) { $this->mFilter = $subpage; $view = 'AbuseFilterViewEdit'; $pageType = 'edit'; } - if ( $subpage == 'import' ) { + if ( $subpage === 'import' ) { $view = 'AbuseFilterViewImport'; $pageType = 'import'; } @@ -128,7 +128,7 @@ class SpecialAbuseFilter extends SpecialPage { public function loadParameters( $subpage ) { $filter = $subpage; - if ( !is_numeric( $filter ) && $filter != 'new' ) { + if ( !is_numeric( $filter ) && $filter !== 'new' ) { $filter = $this->getRequest()->getIntOrNull( 'wpFilter' ); } $this->mFilter = $filter; diff --git a/includes/special/SpecialAbuseLog.php b/includes/special/SpecialAbuseLog.php index f114a52da..bcce5b917 100644 --- a/includes/special/SpecialAbuseLog.php +++ b/includes/special/SpecialAbuseLog.php @@ -398,7 +398,7 @@ class SpecialAbuseLog extends SpecialPage { } if ( $this->mSearchWiki ) { - if ( $this->mSearchWiki == wfWikiID() ) { + if ( $this->mSearchWiki === wfWikiID() ) { $conds['afl_wiki'] = null; } else { $conds['afl_wiki'] = $this->mSearchWiki; @@ -438,9 +438,9 @@ class SpecialAbuseLog extends SpecialPage { } if ( self::canSeeHidden() ) { - if ( $this->mSearchEntries == '1' ) { + if ( $this->mSearchEntries === '1' ) { $conds['afl_deleted'] = 1; - } elseif ( $this->mSearchEntries == '2' ) { + } elseif ( $this->mSearchEntries === '2' ) { $conds[] = self::getNotDeletedCond( $dbr ); } } @@ -450,7 +450,7 @@ class SpecialAbuseLog extends SpecialPage { 'afl_rev_id' => null, 'afl_log_id' => null, ], LIST_AND ); - if ( $this->mSearchImpact == '1' ) { + if ( $this->mSearchImpact === '1' ) { $conds[] = "NOT ( $unsuccessfulActionConds )"; } else { $conds[] = $unsuccessfulActionConds; @@ -559,7 +559,7 @@ class SpecialAbuseLog extends SpecialPage { $out->addJsConfigVars( 'wgAbuseFilterVariables', $vars->dumpAllVars( true ) ); // Diff, if available - if ( $vars && $vars->getVar( 'action' )->toString() == 'edit' ) { + if ( $vars && $vars->getVar( 'action' )->toString() === 'edit' ) { $old_wikitext = $vars->getVar( 'old_wikitext' )->toString(); $new_wikitext = $vars->getVar( 'new_wikitext' )->toString(); @@ -1107,7 +1107,7 @@ class SpecialAbuseLog extends SpecialPage { } if ( $row->afl_rev_id ) { $revision = Revision::newFromId( $row->afl_rev_id ); - if ( $revision && $revision->getVisibility() != 0 ) { + if ( $revision && $revision->getVisibility() !== 0 ) { return 'implicit'; } } diff --git a/maintenance/addMissingLoggingEntries.php b/maintenance/addMissingLoggingEntries.php index 88c93bd4b..bddddd00b 100644 --- a/maintenance/addMissingLoggingEntries.php +++ b/maintenance/addMissingLoggingEntries.php @@ -74,7 +74,7 @@ class AddMissingLoggingEntries extends Maintenance { $count = 0; foreach ( $afhRows as $row ) { - if ( $count % 100 == 0 ) { + if ( $count % 100 === 0 ) { wfWaitForSlaves(); } $user = User::newFromAnyId( $row->afh_user, $row->afh_user_text, null ); diff --git a/tests/legacyParserTest.php b/tests/legacyParserTest.php index c3055c155..542aefd1f 100644 --- a/tests/legacyParserTest.php +++ b/tests/legacyParserTest.php @@ -19,7 +19,7 @@ foreach ( $tests as $test ) { $result = substr( $test, 0, -2 ) . ".r"; $rule = trim( file_get_contents( $test ) ); - $output = trim( file_get_contents( $result ) ) == 'MATCH'; + $output = trim( file_get_contents( $result ) ) === 'MATCH'; $testname = basename( $test ); @@ -29,7 +29,7 @@ foreach ( $tests as $test ) { $check++; $actual = intval( $tester->parse( $rule ) ); - if ( $actual == $output ) { + if ( $actual === $output ) { print "-PASSED.\n"; $pass++; } else {