mirror of
https://github.com/formbricks/formbricks.git
synced 2026-02-22 18:18:45 -06:00
fix: ios package sonarqube fixes (#5249)
This commit is contained in:
@@ -14,7 +14,13 @@ import Network
|
||||
static internal var service = FormbricksService()
|
||||
|
||||
// make this class not instantiatable outside of the SDK
|
||||
internal override init() {}
|
||||
internal override init() {
|
||||
/*
|
||||
This empty initializer prevents external instantiation of the Formbricks class.
|
||||
All methods are static and the class serves as a namespace for the SDK,
|
||||
so instance creation is not needed and should be restricted.
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
Initializes the Formbricks SDK with the given config ``FormbricksConfig``.
|
||||
|
||||
@@ -22,7 +22,7 @@ struct AnyCodable: Codable {
|
||||
}
|
||||
}
|
||||
|
||||
extension AnyCodable: _AnyEncodable, _AnyDecodable {}
|
||||
extension AnyCodable: AnyEncodableProtocol, AnyDecodableProtocol {}
|
||||
|
||||
extension AnyCodable: Equatable {
|
||||
public static func == (lhs: AnyCodable, rhs: AnyCodable) -> Bool {
|
||||
@@ -88,12 +88,10 @@ extension AnyCodable: CustomStringConvertible {
|
||||
|
||||
extension AnyCodable: CustomDebugStringConvertible {
|
||||
public var debugDescription: String {
|
||||
switch value {
|
||||
case let value as CustomDebugStringConvertible:
|
||||
if let value = value as? CustomDebugStringConvertible {
|
||||
return "AnyCodable(\(value.debugDescription))"
|
||||
default:
|
||||
return "AnyCodable(\(description))"
|
||||
}
|
||||
return "AnyCodable(\(description))"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -42,14 +42,14 @@ struct AnyDecodable: Decodable {
|
||||
}
|
||||
|
||||
@usableFromInline
|
||||
protocol _AnyDecodable {
|
||||
protocol AnyDecodableProtocol {
|
||||
var value: Any { get }
|
||||
init<T>(_ value: T?)
|
||||
}
|
||||
|
||||
extension AnyDecodable: _AnyDecodable {}
|
||||
extension AnyDecodable: AnyDecodableProtocol {}
|
||||
|
||||
extension _AnyDecodable {
|
||||
extension AnyDecodableProtocol {
|
||||
public init(from decoder: Decoder) throws {
|
||||
let container = try decoder.singleValueContainer()
|
||||
|
||||
@@ -139,10 +139,9 @@ extension AnyDecodable: CustomStringConvertible {
|
||||
|
||||
extension AnyDecodable: CustomDebugStringConvertible {
|
||||
public var debugDescription: String {
|
||||
switch value {
|
||||
case let value as CustomDebugStringConvertible:
|
||||
if let value = value as? CustomDebugStringConvertible {
|
||||
return "AnyDecodable(\(value.debugDescription))"
|
||||
default:
|
||||
} else {
|
||||
return "AnyDecodable(\(description))"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,16 +40,16 @@ struct AnyEncodable: Encodable {
|
||||
}
|
||||
|
||||
@usableFromInline
|
||||
protocol _AnyEncodable {
|
||||
protocol AnyEncodableProtocol {
|
||||
var value: Any { get }
|
||||
init<T>(_ value: T?)
|
||||
}
|
||||
|
||||
extension AnyEncodable: _AnyEncodable {}
|
||||
extension AnyEncodable: AnyEncodableProtocol {}
|
||||
|
||||
// MARK: - Encodable
|
||||
|
||||
extension _AnyEncodable {
|
||||
extension AnyEncodableProtocol {
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.singleValueContainer()
|
||||
|
||||
@@ -199,10 +199,9 @@ extension AnyEncodable: CustomStringConvertible {
|
||||
|
||||
extension AnyEncodable: CustomDebugStringConvertible {
|
||||
public var debugDescription: String {
|
||||
switch value {
|
||||
case let value as CustomDebugStringConvertible:
|
||||
if let value = value as? CustomDebugStringConvertible {
|
||||
return "AnyEncodable(\(value.debugDescription))"
|
||||
default:
|
||||
} else {
|
||||
return "AnyEncodable(\(description))"
|
||||
}
|
||||
}
|
||||
@@ -217,7 +216,7 @@ extension AnyEncodable: ExpressibleByStringInterpolation {}
|
||||
extension AnyEncodable: ExpressibleByArrayLiteral {}
|
||||
extension AnyEncodable: ExpressibleByDictionaryLiteral {}
|
||||
|
||||
extension _AnyEncodable {
|
||||
extension AnyEncodableProtocol {
|
||||
public init(nilLiteral _: ()) {
|
||||
self.init(nil as Any?)
|
||||
}
|
||||
|
||||
@@ -3,7 +3,12 @@ import SwiftUI
|
||||
/// Presents a survey webview to the window's root
|
||||
final class PresentSurveyManager {
|
||||
static let shared = PresentSurveyManager()
|
||||
private init() { }
|
||||
private init() {
|
||||
/*
|
||||
This empty initializer prevents external instantiation of the PresentSurveyManager class.
|
||||
The class serves as a namespace for the present method, so instance creation is not needed and should be restricted.
|
||||
*/
|
||||
}
|
||||
|
||||
/// The view controller that will present the survey window.
|
||||
private weak var viewController: UIViewController?
|
||||
@@ -29,6 +34,4 @@ final class PresentSurveyManager {
|
||||
func dismissView() {
|
||||
viewController?.dismiss(animated: true)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -4,7 +4,12 @@ import SwiftUI
|
||||
/// Filtering surveys based on the user's segments, responses, and displays.
|
||||
final class SurveyManager {
|
||||
static let shared = SurveyManager()
|
||||
private init() { }
|
||||
private init() {
|
||||
/*
|
||||
This empty initializer prevents external instantiation of the SurveyManager class.
|
||||
The class serves as a namespace for the shared instance, so instance creation is not needed and should be restricted.
|
||||
*/
|
||||
}
|
||||
|
||||
private static let environmentResponseObjectKey = "environmentResponseObjectKey"
|
||||
internal var service = FormbricksService()
|
||||
@@ -124,7 +129,7 @@ private extension SurveyManager {
|
||||
if let environmentResponse = environmentResponse {
|
||||
PresentSurveyManager.shared.present(environmentResponse: environmentResponse, id: id)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// Starts a timer to refresh the environment state after the given timeout (`expiresAt`).
|
||||
@@ -200,7 +205,9 @@ private extension SurveyManager {
|
||||
|
||||
case .displaySome:
|
||||
if let limit = survey.displayLimit {
|
||||
if responses.contains(where: { $0 == survey.id }) { return false }
|
||||
if responses.contains(where: { $0 == survey.id }) {
|
||||
return false
|
||||
}
|
||||
return displays.filter { $0.surveyId == survey.id }.count < limit
|
||||
} else {
|
||||
return true
|
||||
@@ -236,5 +243,5 @@ private extension SurveyManager {
|
||||
return segments.contains(segmentId)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -3,7 +3,12 @@ import Foundation
|
||||
/// Store and manage user state and sync with the server when needed.
|
||||
final class UserManager {
|
||||
static let shared = UserManager()
|
||||
private init() { }
|
||||
private init() {
|
||||
/*
|
||||
This empty initializer prevents external instantiation of the UserManager class.
|
||||
The class serves as a namespace for the user state, so instance creation is not needed and should be restricted.
|
||||
*/
|
||||
}
|
||||
|
||||
private static let userIdKey = "userIdKey"
|
||||
private static let contactIdKey = "contactIdKey"
|
||||
|
||||
@@ -54,8 +54,7 @@ class APIClient<Request: CodableRequest>: Operation, @unchecked Sendable {
|
||||
responseLogMessage.append(urlString)
|
||||
}
|
||||
|
||||
switch httpStatus.responseType {
|
||||
case .success:
|
||||
if httpStatus.responseType == .success {
|
||||
guard let data = data else {
|
||||
self.completion?(.failure(FormbricksAPIClientError(type: .invalidResponse, statusCode: httpStatus.rawValue)))
|
||||
return
|
||||
@@ -73,12 +72,12 @@ class APIClient<Request: CodableRequest>: Operation, @unchecked Sendable {
|
||||
Formbricks.logger.info(responseLogMessage)
|
||||
|
||||
// We want to save the entire response dictionary for the environment response
|
||||
if var environmentResponse = body as? EnvironmentResponse {
|
||||
if let jsonString = String(data: data, encoding: .utf8) {
|
||||
environmentResponse.responseString = jsonString
|
||||
body = environmentResponse as! Request.Response
|
||||
}
|
||||
if var environmentResponse = body as? EnvironmentResponse,
|
||||
let jsonString = String(data: data, encoding: .utf8) {
|
||||
environmentResponse.responseString = jsonString
|
||||
body = environmentResponse as! Request.Response
|
||||
}
|
||||
|
||||
|
||||
self.completion?(.success(body))
|
||||
}
|
||||
@@ -111,8 +110,7 @@ class APIClient<Request: CodableRequest>: Operation, @unchecked Sendable {
|
||||
Formbricks.logger.error(responseLogMessage)
|
||||
self.completion?(.failure(FormbricksAPIClientError(type: .invalidResponse, statusCode: httpStatus.rawValue)))
|
||||
}
|
||||
|
||||
default:
|
||||
} else {
|
||||
if let error = error {
|
||||
responseLogMessage.append("\nError: \(error.localizedDescription)")
|
||||
Formbricks.logger.error(responseLogMessage)
|
||||
|
||||
@@ -20,7 +20,7 @@ enum HTTPStatusCode: Int, Error {
|
||||
// MARK: - Informational - 1xx -
|
||||
|
||||
/// - continue: The server has received the request headers and the client should proceed to send the request body.
|
||||
case `continue` = 100
|
||||
case httpContinue = 100
|
||||
|
||||
/// - switchingProtocols: The requester has asked the server to switch protocols and the server has agreed to do so.
|
||||
case switchingProtocols = 101
|
||||
|
||||
@@ -45,7 +45,13 @@ struct SurveyWebView: UIViewRepresentable {
|
||||
HTTPCookieStorage.shared.removeCookies(since: Date.distantPast)
|
||||
WKWebsiteDataStore.default().fetchDataRecords(ofTypes: WKWebsiteDataStore.allWebsiteDataTypes()) { records in
|
||||
records.forEach { record in
|
||||
WKWebsiteDataStore.default().removeData(ofTypes: record.dataTypes, for: [record], completionHandler: {})
|
||||
WKWebsiteDataStore.default().removeData(ofTypes: record.dataTypes, for: [record], completionHandler: {
|
||||
/*
|
||||
This completion handler is intentionally empty since we only need to
|
||||
ensure the data is removed. No additional actions are required after
|
||||
the website data has been cleared.
|
||||
*/
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -56,7 +62,13 @@ extension SurveyWebView {
|
||||
// webView function handles Javascipt alert
|
||||
func webView(_ webView: WKWebView, runJavaScriptAlertPanelWithMessage message: String, initiatedByFrame frame: WKFrameInfo, completionHandler: @escaping () -> Void) {
|
||||
let alertController = UIAlertController(title: "", message: message, preferredStyle: .alert)
|
||||
alertController.addAction(UIAlertAction(title: "OK", style: .default) { _ in })
|
||||
alertController.addAction(UIAlertAction(title: "OK", style: .default) { _ in
|
||||
/*
|
||||
This closure is intentionally empty since we only need a simple OK button
|
||||
to dismiss the alert. The alert dismissal is handled automatically by the
|
||||
system when the button is tapped.
|
||||
*/
|
||||
})
|
||||
UIApplication.safeKeyWindow?.rootViewController?.presentedViewController?.present(alertController, animated: true)
|
||||
completionHandler()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user