Skip to content

Commit

Permalink
added fromNullable to reduces repetitive logic
Browse files Browse the repository at this point in the history
  • Loading branch information
gbubemismith committed Oct 13, 2023
1 parent 186eb39 commit ce5fc9c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
23 changes: 11 additions & 12 deletions libs/common/src/models/export/fido2-credential.export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,17 @@ export class Fido2CredentialExport {
}

static toDomain(req: Fido2CredentialExport, domain = new Fido2Credential()) {
domain.credentialId = req.credentialId != null ? new EncString(req.credentialId) : null;
domain.keyType = req.keyType != null ? new EncString(req.keyType) : null;
domain.keyAlgorithm = req.keyAlgorithm != null ? new EncString(req.keyAlgorithm) : null;
domain.keyCurve = req.keyCurve != null ? new EncString(req.keyCurve) : null;
domain.keyValue = req.keyValue != null ? new EncString(req.keyValue) : null;
domain.rpId = req.rpId != null ? new EncString(req.rpId) : null;
domain.userHandle = req.userHandle != null ? new EncString(req.userHandle) : null;
domain.counter = req.counter != null ? new EncString(req.counter) : null;
domain.rpName = req.rpName != null ? new EncString(req.rpName) : null;
domain.userDisplayName =
req.userDisplayName != null ? new EncString(req.userDisplayName) : null;
domain.discoverable = req.discoverable != null ? new EncString(req.discoverable) : null;
domain.credentialId = EncString.fromNullable(req.credentialId);
domain.keyType = EncString.fromNullable(req.keyType);
domain.keyAlgorithm = EncString.fromNullable(req.keyAlgorithm);
domain.keyCurve = EncString.fromNullable(req.keyCurve);
domain.keyValue = EncString.fromNullable(req.keyValue);
domain.rpId = EncString.fromNullable(req.rpId);
domain.userHandle = EncString.fromNullable(req.userHandle);
domain.counter = EncString.fromNullable(req.counter);
domain.rpName = EncString.fromNullable(req.rpName);
domain.userDisplayName = EncString.fromNullable(req.userDisplayName);
domain.discoverable = EncString.fromNullable(req.discoverable);

Check notice on line 50 in libs/common/src/models/export/fido2-credential.export.ts

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (EC-598-beeep-properly-store-passkeys-in-bitwarden)

✅ No longer an issue: Complex Method

Fido2CredentialExport.toDomain is no longer above the threshold for cyclomatic complexity. This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring.
domain.creationDate = req.creationDate;
return domain;
}
Expand Down
4 changes: 4 additions & 0 deletions libs/common/src/platform/models/domain/enc-string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ export class EncString implements Encrypted {
return this.encryptedString;
}

static fromNullable(val: string | null) {
return val ? new EncString(val) : null;
}

static fromJSON(obj: Jsonify<EncString>): EncString {
if (obj == null) {
return null;
Expand Down

0 comments on commit ce5fc9c

Please sign in to comment.