diff --git a/src/applications/passphrase/controller/PassphraseCredentialEditController.php b/src/applications/passphrase/controller/PassphraseCredentialEditController.php index 063e8eca26..b8126cf476 100644 --- a/src/applications/passphrase/controller/PassphraseCredentialEditController.php +++ b/src/applications/passphrase/controller/PassphraseCredentialEditController.php @@ -26,23 +26,18 @@ final class PassphraseCredentialEditController extends PassphraseController { return new Aphront404Response(); } - $type = PassphraseCredentialType::getTypeByConstant( - $credential->getCredentialType()); - if (!$type) { - throw new Exception(pht('Credential has invalid type "%s"!', $type)); - } - - if (!$type->isCreateable()) { - throw new Exception( - pht('Credential has noncreateable type "%s"!', $type)); - } + $type = $this->getCredentialType($credential->getCredentialType()); $is_new = false; } else { $type_const = $request->getStr('type'); - $type = PassphraseCredentialType::getTypeByConstant($type_const); - if (!$type) { - return new Aphront404Response(); + $type = $this->getCredentialType($type_const); + + if (!$type->isCreateable()) { + throw new Exception( + pht( + 'Credential has noncreateable type "%s"!', + $credential->getCredentialType())); } $credential = PassphraseCredential::initializeNewCredential($viewer) @@ -358,4 +353,15 @@ final class PassphraseCredentialEditController extends PassphraseController { )); } + private function getCredentialType($type_const) { + $type = PassphraseCredentialType::getTypeByConstant($type_const); + + if (!$type) { + throw new Exception( + pht('Credential has invalid type "%s"!', $type_const)); + } + + return $type; + } + }