From 4d1711fe3d46600b18362ab8036f897e927b59c0 Mon Sep 17 00:00:00 2001 From: Andre Klapper Date: Mon, 3 Nov 2025 07:45:07 +0100 Subject: [PATCH] Merge duplicate branches in switch/case statements Summary: Simplify code by merging statements which contain the very same code. Test Plan: Read and compare code. Reviewers: O1 Blessed Committers, mainframe98 Reviewed By: O1 Blessed Committers, mainframe98 Subscribers: tobiaswiese, valerio.bozzolan, Matthew, Cigaryno Differential Revision: https://we.phorge.it/D26479 --- .../storage/PhabricatorAuditTransaction.php | 7 ++---- .../PhabricatorCalendarImportEditor.php | 2 -- .../calendar/parser/ics/PhutilICSParser.php | 22 ++++--------------- .../storage/PhabricatorCalendarEvent.php | 1 - .../ConpherenceUpdateController.php | 4 +--- ...habricatorDashboardPanelTabsController.php | 2 -- .../storage/DifferentialTransaction.php | 9 ++------ .../DiffusionPathValidateController.php | 4 +--- .../DiffusionSubversionWireProtocol.php | 4 +--- .../worker/DrydockResourceUpdateWorker.php | 3 +-- .../conduit/FeedQueryConduitAPIMethod.php | 2 -- .../PhabricatorJupyterDocumentEngine.php | 7 ------ .../herald/adapter/HeraldAdapter.php | 3 +-- ...habricatorApplicationTransactionEditor.php | 12 ++++------ .../PhabricatorApplicationTransaction.php | 3 +-- 15 files changed, 18 insertions(+), 67 deletions(-) diff --git a/src/applications/audit/storage/PhabricatorAuditTransaction.php b/src/applications/audit/storage/PhabricatorAuditTransaction.php index 69c7a3b045..80b1c025ef 100644 --- a/src/applications/audit/storage/PhabricatorAuditTransaction.php +++ b/src/applications/audit/storage/PhabricatorAuditTransaction.php @@ -148,11 +148,10 @@ final class PhabricatorAuditTransaction case PhabricatorAuditActionConstants::CONCERN: return 'fa-exclamation-circle'; case PhabricatorAuditActionConstants::ACCEPT: + case PhabricatorAuditActionConstants::CLOSE: return 'fa-check'; case PhabricatorAuditActionConstants::RESIGN: return 'fa-plane'; - case PhabricatorAuditActionConstants::CLOSE: - return 'fa-check'; } } @@ -470,6 +469,7 @@ final class PhabricatorAuditTransaction $tags[] = self::MAILTAG_ACTION_RESIGN; break; case DiffusionCommitAuditorsTransaction::TRANSACTIONTYPE: + case PhabricatorAuditActionConstants::ADD_AUDITORS: $tags[] = self::MAILTAG_ADD_AUDITORS; break; case PhabricatorAuditActionConstants::ACTION: @@ -488,9 +488,6 @@ final class PhabricatorAuditTransaction break; } break; - case PhabricatorAuditActionConstants::ADD_AUDITORS: - $tags[] = self::MAILTAG_ADD_AUDITORS; - break; case PhabricatorAuditActionConstants::ADD_CCS: $tags[] = self::MAILTAG_ADD_CCS; break; diff --git a/src/applications/calendar/editor/PhabricatorCalendarImportEditor.php b/src/applications/calendar/editor/PhabricatorCalendarImportEditor.php index f168523988..75dc392e25 100644 --- a/src/applications/calendar/editor/PhabricatorCalendarImportEditor.php +++ b/src/applications/calendar/editor/PhabricatorCalendarImportEditor.php @@ -44,8 +44,6 @@ final class PhabricatorCalendarImportEditor $should_reload = true; break; case PhabricatorCalendarImportFrequencyTransaction::TRANSACTIONTYPE: - $should_trigger = true; - break; case PhabricatorCalendarImportDisableTransaction::TRANSACTIONTYPE: $should_trigger = true; break; diff --git a/src/applications/calendar/parser/ics/PhutilICSParser.php b/src/applications/calendar/parser/ics/PhutilICSParser.php index 0193f6c5a2..f40bf14397 100644 --- a/src/applications/calendar/parser/ics/PhutilICSParser.php +++ b/src/applications/calendar/parser/ics/PhutilICSParser.php @@ -484,6 +484,9 @@ final class PhutilICSParser extends Phobject { $result = $map[$result]; break; case 'CAL-ADDRESS': + case 'RECUR': + case 'URI': + case 'UTC-OFFSET': $result = $data; break; case 'DATE': @@ -491,12 +494,6 @@ final class PhutilICSParser extends Phobject { $result = explode(',', $data); break; case 'DATE-TIME': - if (!strlen($data)) { - $result = array(); - } else { - $result = explode(',', $data); - } - break; case 'DURATION': if (!strlen($data)) { $result = array(); @@ -517,23 +514,12 @@ final class PhutilICSParser extends Phobject { } break; case 'PERIOD': + case 'TIME': $result = explode(',', $data); break; - case 'RECUR': - $result = $data; - break; case 'TEXT': $result = $this->unescapeTextValue($data); break; - case 'TIME': - $result = explode(',', $data); - break; - case 'URI': - $result = $data; - break; - case 'UTC-OFFSET': - $result = $data; - break; default: // RFC5545 says we MUST preserve the data for any types we don't // recognize. diff --git a/src/applications/calendar/storage/PhabricatorCalendarEvent.php b/src/applications/calendar/storage/PhabricatorCalendarEvent.php index 599027437f..6e349055e2 100644 --- a/src/applications/calendar/storage/PhabricatorCalendarEvent.php +++ b/src/applications/calendar/storage/PhabricatorCalendarEvent.php @@ -675,7 +675,6 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO $status = $this->getUserInviteStatus($viewer_phid); switch ($status) { case PhabricatorCalendarEventInvitee::STATUS_ATTENDING: - return 'green'; case PhabricatorCalendarEventInvitee::STATUS_INVITED: return 'green'; case PhabricatorCalendarEventInvitee::STATUS_DECLINED: diff --git a/src/applications/conpherence/controller/ConpherenceUpdateController.php b/src/applications/conpherence/controller/ConpherenceUpdateController.php index cbac0779db..9a4643ddf2 100644 --- a/src/applications/conpherence/controller/ConpherenceUpdateController.php +++ b/src/applications/conpherence/controller/ConpherenceUpdateController.php @@ -325,11 +325,9 @@ final class ConpherenceUpdateController $need_transactions = false; switch ($action) { + case ConpherenceUpdateActions::ADD_PERSON: case ConpherenceUpdateActions::LOAD: - $need_transactions = true; - break; case ConpherenceUpdateActions::MESSAGE: - case ConpherenceUpdateActions::ADD_PERSON: $need_transactions = true; break; case ConpherenceUpdateActions::REMOVE_PERSON: diff --git a/src/applications/dashboard/controller/panel/PhabricatorDashboardPanelTabsController.php b/src/applications/dashboard/controller/panel/PhabricatorDashboardPanelTabsController.php index 7ea0345ceb..b6e847acb3 100644 --- a/src/applications/dashboard/controller/panel/PhabricatorDashboardPanelTabsController.php +++ b/src/applications/dashboard/controller/panel/PhabricatorDashboardPanelTabsController.php @@ -114,8 +114,6 @@ final class PhabricatorDashboardPanelTabsController switch (phid_get_type($context_phid)) { case PhabricatorDashboardDashboardPHIDType::TYPECONST: - $cancel_uri = $context->getURI(); - break; case PhabricatorDashboardPanelPHIDType::TYPECONST: $cancel_uri = $context->getURI(); break; diff --git a/src/applications/differential/storage/DifferentialTransaction.php b/src/applications/differential/storage/DifferentialTransaction.php index 793fe79000..9d67492523 100644 --- a/src/applications/differential/storage/DifferentialTransaction.php +++ b/src/applications/differential/storage/DifferentialTransaction.php @@ -418,9 +418,8 @@ final class DifferentialTransaction case DifferentialAction::ACTION_RECLAIM: case DifferentialAction::ACTION_REOPEN: return 'fa-bullhorn'; - case DifferentialAction::ACTION_RESIGN: - return 'fa-flag'; case DifferentialAction::ACTION_CLAIM: + case DifferentialAction::ACTION_RESIGN: return 'fa-flag'; default: break; @@ -468,19 +467,15 @@ final class DifferentialTransaction case self::TYPE_ACTION: switch ($this->getNewValue()) { case DifferentialAction::ACTION_CLOSE: + case DifferentialAction::ACTION_ABANDON: return PhabricatorTransactions::COLOR_INDIGO; case DifferentialAction::ACTION_ACCEPT: return PhabricatorTransactions::COLOR_GREEN; case DifferentialAction::ACTION_REJECT: - return PhabricatorTransactions::COLOR_RED; - case DifferentialAction::ACTION_ABANDON: - return PhabricatorTransactions::COLOR_INDIGO; case DifferentialAction::ACTION_RETHINK: return PhabricatorTransactions::COLOR_RED; case DifferentialAction::ACTION_REQUEST: - return PhabricatorTransactions::COLOR_SKY; case DifferentialAction::ACTION_RECLAIM: - return PhabricatorTransactions::COLOR_SKY; case DifferentialAction::ACTION_REOPEN: return PhabricatorTransactions::COLOR_SKY; case DifferentialAction::ACTION_RESIGN: diff --git a/src/applications/diffusion/controller/DiffusionPathValidateController.php b/src/applications/diffusion/controller/DiffusionPathValidateController.php index 62e9e04796..7644cd3575 100644 --- a/src/applications/diffusion/controller/DiffusionPathValidateController.php +++ b/src/applications/diffusion/controller/DiffusionPathValidateController.php @@ -32,10 +32,8 @@ final class DiffusionPathValidateController extends DiffusionController { if (!$valid) { switch ($browse_results->getReasonForEmptyResultSet()) { - case DiffusionBrowseResultSet::REASON_IS_FILE: - $valid = true; - break; case DiffusionBrowseResultSet::REASON_IS_EMPTY: + case DiffusionBrowseResultSet::REASON_IS_FILE: $valid = true; break; } diff --git a/src/applications/diffusion/protocol/DiffusionSubversionWireProtocol.php b/src/applications/diffusion/protocol/DiffusionSubversionWireProtocol.php index 251967f314..e13db57f38 100644 --- a/src/applications/diffusion/protocol/DiffusionSubversionWireProtocol.php +++ b/src/applications/diffusion/protocol/DiffusionSubversionWireProtocol.php @@ -134,10 +134,8 @@ final class DiffusionSubversionWireProtocol extends Phobject { $value = $item['value']; $type = $item['type']; switch ($type) { - case 'word': - $out[] = $value; - break; case 'number': + case 'word': $out[] = $value; break; case 'string': diff --git a/src/applications/drydock/worker/DrydockResourceUpdateWorker.php b/src/applications/drydock/worker/DrydockResourceUpdateWorker.php index 324639bd51..f69c787285 100644 --- a/src/applications/drydock/worker/DrydockResourceUpdateWorker.php +++ b/src/applications/drydock/worker/DrydockResourceUpdateWorker.php @@ -71,14 +71,13 @@ final class DrydockResourceUpdateWorker extends DrydockWorker { $this->activateResource($resource); break; case DrydockResourceStatus::STATUS_ACTIVE: + case DrydockResourceStatus::STATUS_DESTROYED: // Nothing to do. break; case DrydockResourceStatus::STATUS_RELEASED: case DrydockResourceStatus::STATUS_BROKEN: $this->destroyResource($resource); break; - case DrydockResourceStatus::STATUS_DESTROYED: - // Nothing to do. break; } diff --git a/src/applications/feed/conduit/FeedQueryConduitAPIMethod.php b/src/applications/feed/conduit/FeedQueryConduitAPIMethod.php index dfd265f006..b6b396731c 100644 --- a/src/applications/feed/conduit/FeedQueryConduitAPIMethod.php +++ b/src/applications/feed/conduit/FeedQueryConduitAPIMethod.php @@ -107,8 +107,6 @@ final class FeedQueryConduitAPIMethod extends FeedConduitAPIMethod { switch ($view_type) { case 'html': - $data = $view->render(); - break; case 'html-summary': $data = $view->render(); break; diff --git a/src/applications/files/document/PhabricatorJupyterDocumentEngine.php b/src/applications/files/document/PhabricatorJupyterDocumentEngine.php index 7f1366df71..08e4b59635 100644 --- a/src/applications/files/document/PhabricatorJupyterDocumentEngine.php +++ b/src/applications/files/document/PhabricatorJupyterDocumentEngine.php @@ -201,13 +201,6 @@ final class PhabricatorJupyterDocumentEngine switch ($type) { case '-': - $result[] = phutil_tag( - 'span', - array( - 'class' => 'bright', - ), - $text); - break; case '+': $result[] = phutil_tag( 'span', diff --git a/src/applications/herald/adapter/HeraldAdapter.php b/src/applications/herald/adapter/HeraldAdapter.php index 82665e420f..4585c36f2d 100644 --- a/src/applications/herald/adapter/HeraldAdapter.php +++ b/src/applications/herald/adapter/HeraldAdapter.php @@ -512,12 +512,11 @@ abstract class HeraldAdapter extends Phobject { $condition_value); case self::CONDITION_EXISTS: case self::CONDITION_IS_TRUE: + case self::CONDITION_UNCONDITIONALLY: return (bool)$field_value; case self::CONDITION_NOT_EXISTS: case self::CONDITION_IS_FALSE: return !$field_value; - case self::CONDITION_UNCONDITIONALLY: - return (bool)$field_value; case self::CONDITION_NEVER: return false; case self::CONDITION_REGEXP: diff --git a/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php b/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php index e193a2d2b9..e31c4c09ec 100644 --- a/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php +++ b/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php @@ -505,11 +505,12 @@ abstract class PhabricatorApplicationTransactionEditor switch ($type) { case PhabricatorTransactions::TYPE_CREATE: case PhabricatorTransactions::TYPE_HISTORY: + case PhabricatorTransactions::TYPE_MFA: + case PhabricatorTransactions::TYPE_COMMENT: + case PhabricatorTransactions::TYPE_FILE: return null; case PhabricatorTransactions::TYPE_SUBTYPE: return $object->getEditEngineSubtype(); - case PhabricatorTransactions::TYPE_MFA: - return null; case PhabricatorTransactions::TYPE_SUBSCRIBERS: return array_values($this->subscribers); case PhabricatorTransactions::TYPE_VIEW_POLICY: @@ -578,10 +579,6 @@ abstract class PhabricatorApplicationTransactionEditor // NOTE: Custom fields have their old value pre-populated when they are // built by PhabricatorCustomFieldList. return $xaction->getOldValue(); - case PhabricatorTransactions::TYPE_COMMENT: - return null; - case PhabricatorTransactions::TYPE_FILE: - return null; default: return $this->getCustomTransactionOldValue($object, $xaction); } @@ -602,6 +599,7 @@ abstract class PhabricatorApplicationTransactionEditor switch ($type) { case PhabricatorTransactions::TYPE_CREATE: + case PhabricatorTransactions::TYPE_COMMENT: return null; case PhabricatorTransactions::TYPE_SUBSCRIBERS: return $this->getPHIDTransactionNewValue($xaction); @@ -649,8 +647,6 @@ abstract class PhabricatorApplicationTransactionEditor case PhabricatorTransactions::TYPE_CUSTOMFIELD: $field = $this->getCustomFieldForTransaction($object, $xaction); return $field->getNewValueFromApplicationTransactions($xaction); - case PhabricatorTransactions::TYPE_COMMENT: - return null; default: return $this->getCustomTransactionNewValue($object, $xaction); } diff --git a/src/applications/transactions/storage/PhabricatorApplicationTransaction.php b/src/applications/transactions/storage/PhabricatorApplicationTransaction.php index 6956071edd..71e7e29af0 100644 --- a/src/applications/transactions/storage/PhabricatorApplicationTransaction.php +++ b/src/applications/transactions/storage/PhabricatorApplicationTransaction.php @@ -791,6 +791,7 @@ abstract class PhabricatorApplicationTransaction switch ($this->getTransactionType()) { case PhabricatorTransactions::TYPE_TOKEN: case PhabricatorTransactions::TYPE_MFA: + case PhabricatorTransactions::TYPE_INLINESTATE: return true; case PhabricatorTransactions::TYPE_SUBSCRIBERS: // See T8952. When an application (usually Herald) modifies @@ -815,8 +816,6 @@ abstract class PhabricatorApplicationTransaction break; } break; - case PhabricatorTransactions::TYPE_INLINESTATE: - return true; } return $this->shouldHide(); -- 2.51.2