Skip to content

Commit

Permalink
Merge pull request #298 from omise/fix/MIT-2551-NetceteraThreeDSContr…
Browse files Browse the repository at this point in the history
…oller

Fix SonarCloud "Cognitive Complexity" warning in NetceteraThreeDSController
  • Loading branch information
Andrei Solovev authored Jun 17, 2024
2 parents 133caa6 + ec50d36 commit 7b2d39f
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions OmiseSDK/Sources/3DS/NetceteraThreeDSController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ extension NetceteraThreeDSController: NetceteraThreeDSControllerProtocol {
ThreeDSSDKAppDelegate.shared.appOpened(url: url)
}

// swiftlint:disable:next function_body_length
func processAuthorizedURL(
_ authorizeUrl: URL,
threeDSRequestorAppURL: String?,
Expand Down Expand Up @@ -187,18 +186,8 @@ extension NetceteraThreeDSController: NetceteraThreeDSControllerProtocol {
return
}

switch response.status {
case .success:
onComplete(.success(()))
guard !Self.processAuthenticationResponse(response, onComplete: onComplete) else {
return
case .failed:
onComplete(.failure(NetceteraThreeDSController.Errors.authResStatusFailed))
return
case .unknown:
onComplete(.failure(NetceteraThreeDSController.Errors.authResStatusUnknown(response.serverStatus)))
return
case .challenge:
break
}

DispatchQueue.main.async {
Expand All @@ -222,6 +211,22 @@ extension NetceteraThreeDSController: NetceteraThreeDSControllerProtocol {
}
}

static func processAuthenticationResponse(_ response: AuthResponse, onComplete: ((Result<Void, Error>) -> Void)) -> Bool {
switch response.status {
case .success:
onComplete(.success(()))
return true
case .failed:
onComplete(.failure(NetceteraThreeDSController.Errors.authResStatusFailed))
return true
case .unknown:
onComplete(.failure(NetceteraThreeDSController.Errors.authResStatusUnknown(response.serverStatus)))
return true
case .challenge:
return false
}
}

func prepareChallengeParameters(
aRes: AuthResponse.ARes,
threeDSRequestorAppURL: String?
Expand Down

0 comments on commit 7b2d39f

Please sign in to comment.