1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-22 06:42:42 +01:00

Remove trivial cases of unreachable code

Summary:
Static code analysis can detect `Unreachable statement - code above always terminates.`
The vast majority of occurrences in the Phorge codebase are due to an unreachable `break` within a `case` after a `return` or after an all-covering `if/else`.
All this noise makes it harder to spot real logic issues (there are some!), thus fix these trivial cases.

Test Plan: Examine the code; run static code analysis.

Reviewers: O1 Blessed Committers, valerio.bozzolan

Reviewed By: O1 Blessed Committers, valerio.bozzolan

Subscribers: tobiaswiese, valerio.bozzolan, Matthew, Cigaryno

Differential Revision: https://we.phorge.it/D25802
This commit is contained in:
Andre Klapper 2024-08-24 10:46:56 +02:00
parent 8c3a62d6af
commit 43539b220c
26 changed files with 0 additions and 55 deletions

View file

@ -650,7 +650,6 @@ final class PhabricatorDuoAuthFactor
'You denied this request. Wait %s second(s) to try again.', 'You denied this request. Wait %s second(s) to try again.',
new PhutilNumber($wait_duration))); new PhutilNumber($wait_duration)));
} }
break;
} }
return null; return null;

View file

@ -79,7 +79,6 @@ final class PhabricatorAuthProviderConfigTransaction
'%s disabled this provider.', '%s disabled this provider.',
$this->renderHandleLink($author_phid)); $this->renderHandleLink($author_phid));
} }
break;
case self::TYPE_LOGIN: case self::TYPE_LOGIN:
if ($new) { if ($new) {
return pht( return pht(
@ -90,7 +89,6 @@ final class PhabricatorAuthProviderConfigTransaction
'%s disabled login.', '%s disabled login.',
$this->renderHandleLink($author_phid)); $this->renderHandleLink($author_phid));
} }
break;
case self::TYPE_REGISTRATION: case self::TYPE_REGISTRATION:
if ($new) { if ($new) {
return pht( return pht(
@ -101,7 +99,6 @@ final class PhabricatorAuthProviderConfigTransaction
'%s disabled registration.', '%s disabled registration.',
$this->renderHandleLink($author_phid)); $this->renderHandleLink($author_phid));
} }
break;
case self::TYPE_LINK: case self::TYPE_LINK:
if ($new) { if ($new) {
return pht( return pht(
@ -112,7 +109,6 @@ final class PhabricatorAuthProviderConfigTransaction
'%s disabled account linking.', '%s disabled account linking.',
$this->renderHandleLink($author_phid)); $this->renderHandleLink($author_phid));
} }
break;
case self::TYPE_UNLINK: case self::TYPE_UNLINK:
if ($new) { if ($new) {
return pht( return pht(
@ -123,7 +119,6 @@ final class PhabricatorAuthProviderConfigTransaction
'%s disabled account unlinking.', '%s disabled account unlinking.',
$this->renderHandleLink($author_phid)); $this->renderHandleLink($author_phid));
} }
break;
case self::TYPE_TRUST_EMAILS: case self::TYPE_TRUST_EMAILS:
if ($new) { if ($new) {
return pht( return pht(
@ -134,7 +129,6 @@ final class PhabricatorAuthProviderConfigTransaction
'%s disabled email trust.', '%s disabled email trust.',
$this->renderHandleLink($author_phid)); $this->renderHandleLink($author_phid));
} }
break;
case self::TYPE_AUTO_LOGIN: case self::TYPE_AUTO_LOGIN:
if ($new) { if ($new) {
return pht( return pht(
@ -145,7 +139,6 @@ final class PhabricatorAuthProviderConfigTransaction
'%s disabled auto login.', '%s disabled auto login.',
$this->renderHandleLink($author_phid)); $this->renderHandleLink($author_phid));
} }
break;
case self::TYPE_PROPERTY: case self::TYPE_PROPERTY:
$provider = $this->getProvider(); $provider = $this->getProvider();
if ($provider) { if ($provider) {
@ -158,7 +151,6 @@ final class PhabricatorAuthProviderConfigTransaction
return pht( return pht(
'%s edited a property of this provider.', '%s edited a property of this provider.',
$this->renderHandleLink($author_phid)); $this->renderHandleLink($author_phid));
break;
} }
return parent::getTitle(); return parent::getTitle();

View file

@ -575,7 +575,6 @@ final class PhutilCalendarRecurrenceRule
pht( pht(
'RRULE specifies BYMONTHDAY with FREQ set to WEEKLY, which '. 'RRULE specifies BYMONTHDAY with FREQ set to WEEKLY, which '.
'violates RFC5545.')); 'violates RFC5545.'));
break;
default: default:
break; break;
} }

View file

@ -45,7 +45,6 @@ final class PhabricatorConfigTransaction
'%s edited this configuration entry.', '%s edited this configuration entry.',
$this->renderHandleLink($author_phid)); $this->renderHandleLink($author_phid));
} }
break;
} }
return parent::getTitle(); return parent::getTitle();
@ -83,7 +82,6 @@ final class PhabricatorConfigTransaction
$this->renderHandleLink($author_phid), $this->renderHandleLink($author_phid),
$this->getObject()->getConfigKey()); $this->getObject()->getConfigKey());
} }
break;
} }
return parent::getTitle(); return parent::getTitle();
@ -145,7 +143,6 @@ final class PhabricatorConfigTransaction
} else { } else {
return PhabricatorTransactions::COLOR_BLUE; return PhabricatorTransactions::COLOR_BLUE;
} }
break;
} }
} }

View file

@ -62,7 +62,6 @@ final class ConpherenceCreateThreadConduitAPIMethod
switch ($error_code) { switch ($error_code) {
case ConpherenceEditor::ERROR_EMPTY_PARTICIPANTS: case ConpherenceEditor::ERROR_EMPTY_PARTICIPANTS:
throw new ConduitException('ERR_EMPTY_PARTICIPANT_PHIDS'); throw new ConduitException('ERR_EMPTY_PARTICIPANT_PHIDS');
break;
} }
} }
} }

View file

@ -139,7 +139,6 @@ final class ConpherenceUpdateController
break; break;
default: default:
throw new Exception(pht('Unknown action: %s', $action)); throw new Exception(pht('Unknown action: %s', $action));
break;
} }
if ($xactions) { if ($xactions) {
@ -173,19 +172,16 @@ final class ConpherenceUpdateController
$latest_transaction_id); $latest_transaction_id);
return id(new AphrontAjaxResponse()) return id(new AphrontAjaxResponse())
->setContent($content); ->setContent($content);
break;
case 'go-home': case 'go-home':
$content = array( $content = array(
'href' => $this->getApplicationURI(), 'href' => $this->getApplicationURI(),
); );
return id(new AphrontAjaxResponse()) return id(new AphrontAjaxResponse())
->setContent($content); ->setContent($content);
break;
case 'redirect': case 'redirect':
default: default:
return id(new AphrontRedirectResponse()) return id(new AphrontRedirectResponse())
->setURI('/'.$conpherence->getMonogram()); ->setURI('/'.$conpherence->getMonogram());
break;
} }
} }
} }

View file

@ -271,7 +271,6 @@ final class ConpherenceThread extends ConpherenceDAO
switch ($capability) { switch ($capability) {
case PhabricatorPolicyCapability::CAN_VIEW: case PhabricatorPolicyCapability::CAN_VIEW:
return pht('Participants in a room can always view it.'); return pht('Participants in a room can always view it.');
break;
} }
} }

View file

@ -88,7 +88,6 @@ final class ConpherenceTransactionView extends AphrontView {
$viewer, $viewer,
'M jS, Y')), 'M jS, Y')),
)); ));
break;
} }
$info = $this->renderTransactionInfo(); $info = $this->renderTransactionInfo();

View file

@ -81,7 +81,6 @@ final class DifferentialCreateCommentConduitAPIMethod
pht( pht(
'Unsupported action "%s".', 'Unsupported action "%s".',
$action)); $action));
break;
} }
} }

View file

@ -252,11 +252,9 @@ final class DifferentialTransaction
$commit_name, $commit_name,
$author_name); $author_name);
} }
break;
default: default:
return DifferentialAction::getBasicStoryText($new, $author_handle); return DifferentialAction::getBasicStoryText($new, $author_handle);
} }
break;
} }
return parent::getTitle(); return parent::getTitle();
@ -366,7 +364,6 @@ final class DifferentialTransaction
$commit_name); $commit_name);
} }
} }
break;
case DifferentialAction::ACTION_REQUEST: case DifferentialAction::ACTION_REQUEST:
return pht( return pht(

View file

@ -162,7 +162,6 @@ abstract class DiffusionQueryConduitAPIMethod
break; break;
default: default:
throw new ConduitException('ERR-UNKNOWN-VCS-TYPE'); throw new ConduitException('ERR-UNKNOWN-VCS-TYPE');
break;
} }
return $result; return $result;
} }

View file

@ -1371,7 +1371,6 @@ final class DiffusionCommitHookEngine extends Phobject {
return id(new DiffusionCommitRef()) return id(new DiffusionCommitRef())
->setMessage($message); ->setMessage($message);
break;
default: default:
throw new Exception(pht("Unknown VCS '%s!'", $vcs)); throw new Exception(pht("Unknown VCS '%s!'", $vcs));
} }

View file

@ -223,7 +223,6 @@ abstract class PhabricatorFeedStory
break; break;
default: default:
throw new Exception(pht('Unknown rendering target: %s', $target)); throw new Exception(pht('Unknown rendering target: %s', $target));
break;
} }
} }

View file

@ -139,6 +139,5 @@ final class PhabricatorFilesManagementRebuildWorkflow
return 0; return 0;
} }
return 0;
} }
} }

View file

@ -1038,13 +1038,10 @@ final class PhabricatorFile extends PhabricatorFileDAO
case 'jpg'; case 'jpg';
case 'jpeg': case 'jpeg':
return function_exists('imagejpeg'); return function_exists('imagejpeg');
break;
case 'png': case 'png':
return function_exists('imagepng'); return function_exists('imagepng');
break;
case 'gif': case 'gif':
return function_exists('imagegif'); return function_exists('imagegif');
break;
default: default:
throw new Exception(pht('Unknown type matched as image MIME type.')); throw new Exception(pht('Unknown type matched as image MIME type.'));
} }

View file

@ -123,7 +123,6 @@ final class PhabricatorFlagQuery
default: default:
throw new Exception( throw new Exception(
pht('Unknown groupBy parameter: %s', $this->groupBy)); pht('Unknown groupBy parameter: %s', $this->groupBy));
break;
} }
return $flags; return $flags;

View file

@ -144,7 +144,6 @@ abstract class HeraldField extends Phobject {
return $tokenizer; return $tokenizer;
} }
break;
} }

View file

@ -54,7 +54,6 @@ final class LegalpadDocumentBody extends LegalpadDAO
break; break;
default: default:
throw new Exception(pht('Unknown field: %s', $field)); throw new Exception(pht('Unknown field: %s', $field));
break;
} }
return $text; return $text;

View file

@ -130,7 +130,6 @@ final class ManiphestTransaction
$this->renderHandleLink($author_phid), $this->renderHandleLink($author_phid),
$this->renderSubtypeName($old), $this->renderSubtypeName($old),
$this->renderSubtypeName($new)); $this->renderSubtypeName($new));
break;
} }
return parent::getTitle(); return parent::getTitle();

View file

@ -266,7 +266,6 @@ final class NuanceGitHubRawEvent extends Phobject {
default: default:
return pht('Ref %s', $ref); return pht('Ref %s', $ref);
} }
break;
case 'PushEvent': case 'PushEvent':
$ref = idxv($raw, array('payload', 'ref')); $ref = idxv($raw, array('payload', 'ref'));
if (preg_match('(^refs/heads/)', $ref)) { if (preg_match('(^refs/heads/)', $ref)) {
@ -274,7 +273,6 @@ final class NuanceGitHubRawEvent extends Phobject {
} else { } else {
return pht('Ref %s', $ref); return pht('Ref %s', $ref);
} }
break;
case 'WatchEvent': case 'WatchEvent':
$actor = idxv($raw, array('actor', 'login')); $actor = idxv($raw, array('actor', 'login'));
return pht('User %s', $actor); return pht('User %s', $actor);
@ -362,7 +360,6 @@ final class NuanceGitHubRawEvent extends Phobject {
default: default:
return pht('"%s"', $action); return pht('"%s"', $action);
} }
break;
case 'IssueCommentEvent': case 'IssueCommentEvent':
$action = idxv($raw, array('payload', 'action')); $action = idxv($raw, array('payload', 'action'));
switch ($action) { switch ($action) {
@ -371,7 +368,6 @@ final class NuanceGitHubRawEvent extends Phobject {
default: default:
return pht('"%s"', $action); return pht('"%s"', $action);
} }
break;
case 'PullRequestEvent': case 'PullRequestEvent':
$action = idxv($raw, array('payload', 'action')); $action = idxv($raw, array('payload', 'action'));
switch ($action) { switch ($action) {
@ -380,7 +376,6 @@ final class NuanceGitHubRawEvent extends Phobject {
default: default:
return pht('"%s"', $action); return pht('"%s"', $action);
} }
break;
case 'WatchEvent': case 'WatchEvent':
return pht('Watched'); return pht('Watched');
} }

View file

@ -222,7 +222,6 @@ final class PhamePost extends PhameDAO
} else { } else {
return PhabricatorPolicies::POLICY_NOONE; return PhabricatorPolicies::POLICY_NOONE;
} }
break;
case PhabricatorPolicyCapability::CAN_EDIT: case PhabricatorPolicyCapability::CAN_EDIT:
if ($this->getBlog()) { if ($this->getBlog()) {
return $this->getBlog()->getEditPolicy(); return $this->getBlog()->getEditPolicy();

View file

@ -318,7 +318,6 @@ final class PhrequentTimeBlock extends Phobject {
} }
} }
return 0;
} }
} }

View file

@ -50,7 +50,6 @@ final class PhabricatorConpherenceSoundSetting
ConpherenceRoomSettings::SOUND_MENTION => ConpherenceRoomSettings::SOUND_MENTION =>
ConpherenceRoomSettings::DEFAULT_MENTION_SOUND, ConpherenceRoomSettings::DEFAULT_MENTION_SOUND,
); );
break;
case self::VALUE_CONPHERENCE_MENTION: case self::VALUE_CONPHERENCE_MENTION:
return array( return array(
ConpherenceRoomSettings::SOUND_RECEIVE => ConpherenceRoomSettings::SOUND_RECEIVE =>
@ -58,7 +57,6 @@ final class PhabricatorConpherenceSoundSetting
ConpherenceRoomSettings::SOUND_MENTION => ConpherenceRoomSettings::SOUND_MENTION =>
ConpherenceRoomSettings::DEFAULT_MENTION_SOUND, ConpherenceRoomSettings::DEFAULT_MENTION_SOUND,
); );
break;
case self::VALUE_CONPHERENCE_SILENT: case self::VALUE_CONPHERENCE_SILENT:
return array( return array(
ConpherenceRoomSettings::SOUND_RECEIVE => ConpherenceRoomSettings::SOUND_RECEIVE =>
@ -66,7 +64,6 @@ final class PhabricatorConpherenceSoundSetting
ConpherenceRoomSettings::SOUND_MENTION => ConpherenceRoomSettings::SOUND_MENTION =>
ConpherenceRoomSettings::DEFAULT_NO_SOUND, ConpherenceRoomSettings::DEFAULT_NO_SOUND,
); );
break;
} }
} }

View file

@ -37,7 +37,6 @@ final class PhabricatorApplicationTransactionValueController
break; break;
default: default:
return new Aphront404Response(); return new Aphront404Response();
break;
} }
if ($type == 'old') { if ($type == 'old') {

View file

@ -678,7 +678,6 @@ abstract class PhabricatorApplicationTransaction
} else { } else {
return false; return false;
} }
break;
case PhabricatorTransactions::TYPE_CUSTOMFIELD: case PhabricatorTransactions::TYPE_CUSTOMFIELD:
$field = $this->getTransactionCustomField(); $field = $this->getTransactionCustomField();
if ($field) { if ($field) {
@ -705,7 +704,6 @@ abstract class PhabricatorApplicationTransaction
return true; return true;
} }
return false; return false;
break;
default: default:
break; break;
} }
@ -1061,7 +1059,6 @@ abstract class PhabricatorApplicationTransaction
'%s updated subscribers...', '%s updated subscribers...',
$this->renderHandleLink($author_phid)); $this->renderHandleLink($author_phid));
} }
break;
case PhabricatorTransactions::TYPE_FILE: case PhabricatorTransactions::TYPE_FILE:
$add = array_diff_key($new, $old); $add = array_diff_key($new, $old);
$add = array_keys($add); $add = array_keys($add);
@ -1179,7 +1176,6 @@ abstract class PhabricatorApplicationTransaction
$this->renderHandleLink($author_phid)); $this->renderHandleLink($author_phid));
} }
break;
case PhabricatorTransactions::TYPE_EDGE: case PhabricatorTransactions::TYPE_EDGE:
$record = PhabricatorEdgeChangeRecord::newFromTransaction($this); $record = PhabricatorEdgeChangeRecord::newFromTransaction($this);
$add = $record->getAddedPHIDs(); $add = $record->getAddedPHIDs();
@ -1275,7 +1271,6 @@ abstract class PhabricatorApplicationTransaction
$this->renderHandleLink($author_phid), $this->renderHandleLink($author_phid),
new PhutilNumber($undone)); new PhutilNumber($undone));
} }
break;
case PhabricatorTransactions::TYPE_COLUMNS: case PhabricatorTransactions::TYPE_COLUMNS:
$moves = $this->getInterestingMoves($new); $moves = $this->getInterestingMoves($new);
@ -1315,8 +1310,6 @@ abstract class PhabricatorApplicationTransaction
phutil_count($moves), phutil_count($moves),
phutil_implode_html(', ', $fragments)); phutil_implode_html(', ', $fragments));
} }
break;
case PhabricatorTransactions::TYPE_MFA: case PhabricatorTransactions::TYPE_MFA:
return pht( return pht(
@ -1490,7 +1483,6 @@ abstract class PhabricatorApplicationTransaction
phutil_count($moves), phutil_count($moves),
phutil_implode_html(', ', $fragments)); phutil_implode_html(', ', $fragments));
} }
break;
case PhabricatorTransactions::TYPE_MFA: case PhabricatorTransactions::TYPE_MFA:
return null; return null;

View file

@ -376,7 +376,6 @@ final class PHUIHeaderView extends AphrontTagView {
break; break;
default: default:
throw new Exception(pht('Incorrect Property Passed')); throw new Exception(pht('Incorrect Property Passed'));
break;
} }
} }