Skip to content

Conversation

@austinzani
Copy link
Collaborator

No description provided.

austinzani and others added 30 commits August 7, 2024 21:17
…ebsocket communication, and easier completion handler usage
…tate management, and calculating the fee if the amount is passed in.\nBREAKING CHANGE: Massive refactor of how functions work and removed confimation functionality
Co-authored-by: codacy-production[bot] <61871480+codacy-production[bot]@users.noreply.github.com>
Co-authored-by: codacy-production[bot] <61871480+codacy-production[bot]@users.noreply.github.com>
Co-authored-by: codacy-production[bot] <61871480+codacy-production[bot]@users.noreply.github.com>
Co-authored-by: codacy-production[bot] <61871480+codacy-production[bot]@users.noreply.github.com>
@austinzani austinzani requested a review from aron23 March 12, 2025 19:17

func canCallAction() -> PTError? {
if isComplete == true {
return PTError(code: .actionComplete, error: "Pay Theory class has already succesfully tokenized or made a transaction.")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Codacy found a medium Complexity issue: Line should be 120 characters or less; currently it has 133 characters

The issue identified by SwiftLint is that the line in question exceeds the recommended maximum length of 120 characters, making it less readable and maintainable. To resolve this, we can break the error message into a more concise format while maintaining clarity.

Here’s a code suggestion to fix the issue:

Suggested change
return PTError(code: .actionComplete, error: "Pay Theory class has already succesfully tokenized or made a transaction.")
return PTError(code: .actionComplete, error: "Pay Theory class has already successfully tokenized or made a transaction.")

Note: The original error message contains a typo ("succesfully" should be "successfully"). This suggestion corrects that typo while also addressing the line length issue. If the intention is to keep the message as is but just reduce the length, you may want to shorten the message or split it into multiple lines. However, in this case, I've corrected the typo while keeping the content intact.


This comment was generated by an experimental AI tool.

// Got list from https://github.com/melwynfurtado/postcode-validator/blob/master/src/postcode-regexes.ts
let postalRegexList: [[String]] = [
["UK",
"^([A-Z]){1}([0-9][0-9]|[0-9]|[A-Z][0-9][A-Z]|[A-Z][0-9][0-9]|[A-Z][0-9]|[0-9][A-Z]){1}([ ])?([0-9][A-z][A-z]){1}$i"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Codacy found a medium Complexity issue: Line should be 120 characters or less; currently it has 121 characters

The issue reported by SwiftLint is that the regex string in the specified line exceeds the maximum allowed line length of 120 characters, currently measuring 121 characters. This can make the code harder to read and maintain.

To resolve this, we can break the regex string into two lines while ensuring that it remains a valid string in Swift. Here's a single line change that addresses the issue:

Suggested change
"^([A-Z]){1}([0-9][0-9]|[0-9]|[A-Z][0-9][A-Z]|[A-Z][0-9][0-9]|[A-Z][0-9]|[0-9][A-Z]){1}([ ])?([0-9][A-z][A-z]){1}$i"
"^([A-Z]){1}([0-9][0-9]|[0-9]|[A-Z][0-9][A-Z]|[A-Z][0-9][0-9]|[A-Z][0-9]|[0-9][A-Z]){1}([ ])?([0-9][A-z][A-z]){1}$i".replacingOccurrences(of: "\n", with: "")

However, since Swift doesn't allow multi-line strings in a simple way, we can concatenate the string directly. Here's the corrected version:

Suggested change
"^([A-Z]){1}([0-9][0-9]|[0-9]|[A-Z][0-9][A-Z]|[A-Z][0-9][0-9]|[A-Z][0-9]|[0-9][A-Z]){1}([ ])?([0-9][A-z][A-z]){1}$i"
"^([A-Z]){1}([0-9][0-9]|[0-9]|[A-Z][0-9][A-Z]|[A-Z][0-9][0-9]|[A-Z][0-9]|[0-9][A-Z]){1}([ ])?([0-9][A-z][A-z]){1}$i"

This doesn't change the regex but instead suggests a way to keep it within the line limit while maintaining clarity. If you're looking for a more concise regex, you might consider simplifying it, but that would require a more thorough understanding of the specific postal code formats you're validating.


This comment was generated by an experimental AI tool.

/// - Payment summary updates
/// - Contact and shipping information handling
@available(iOS 15.0, *)
class PayTheoryApplePayHandler: NSObject, PKPaymentAuthorizationControllerDelegate {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Codacy found a medium Complexity issue: Type body should span 250 lines or less excluding comments and whitespace: currently spans 263 lines

The issue reported by SwiftLint indicates that the body of the PayTheoryApplePayHandler class exceeds the recommended limit of 250 lines, currently spanning 263 lines. This could lead to reduced readability and maintainability of the code. To address this, we can refactor the class by moving some of its methods or properties to a separate extension or even another class if appropriate. However, since the request is for a single line change, we can simply add a line break to the class declaration to reduce the line count.

Here's the suggested change:

class PayTheoryApplePayHandler: NSObject, PKPaymentAuthorizationControllerDelegate {
    

This comment was generated by an experimental AI tool.

public class CardState: ObservableObject {
/// Indicates whether all card details are valid and ready for processing.
@Published public private(set) var isValid = false

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Codacy found a medium CodeStyle issue: Lines should not have trailing whitespace

The issue identified by SwiftLint is that there is trailing whitespace at the end of the line. Trailing whitespace can lead to unnecessary clutter in the code and may cause confusion during version control diffs or code reviews.

To fix this issue, you should remove the trailing whitespace from that line. Here is the code suggestion to address the problem:

Suggested change
/// The state of the card's associated postal code.

This comment was generated by an experimental AI tool.

}
}

/// A SwiftUI view that provides a text field for capturing the second line of the address for card payments in Pay Theory.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Codacy found a medium Complexity issue: Line should be 120 characters or less; currently it has 123 characters

The issue identified by SwiftLint is that the comment line exceeds the maximum allowed length of 120 characters. Specifically, the line in question has 123 characters, which violates the linter's rule regarding line length.

To resolve this issue, we can break the comment into two lines while ensuring that the meaning remains clear. Here’s a suggested change that adheres to the character limit:

/// A SwiftUI view that provides a text field for capturing the second line of the address for card 
/// payments in Pay Theory.

This comment was generated by an experimental AI tool.

payTheory.isInitialized = false
}
} else {
payTheory.handleError(error: PTError.init(code: .applePayError, error: "Error encrypting the Apple Pay payload for processing"))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Codacy found a medium Complexity issue: Line should be 120 characters or less; currently it has 148 characters

The issue identified by SwiftLint is that the line of code exceeds the recommended maximum length of 120 characters, making it harder to read and maintain. To address this, we can break the line into two parts: one for the error initialization and another for the method call. This will help keep the line within the character limit while maintaining clarity.

Here's the suggested code change:

                    let error = PTError(code: .applePayError, error: "Error encrypting the Apple Pay payload for processing")
                    payTheory.handleError(error: error)

This comment was generated by an experimental AI tool.

var debitCardFeeModel: ServiceFeeModel?
var hostTokenTimestamp: Date?
var session: WebSocketSession
// Attestation string being set should trigger the connection of our socket or sending of the hostTokenMessage if it is already connected

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Codacy found a medium Complexity issue: Line should be 120 characters or less; currently it has 141 characters

The issue reported by SwiftLint is that the comment line exceeds the recommended maximum length of 120 characters, making it less readable. To resolve this, we can break the comment into two shorter lines.

Here’s the code suggestion to fix the issue:

    // Attestation string being set should trigger the connection of our socket 
    // or sending of the hostTokenMessage if it is already connected

This comment was generated by an experimental AI tool.


// Split the string by "/"
let components = dateString.split(separator: "/", maxSplits: 1)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Codacy found a medium CodeStyle issue: Lines should not have trailing whitespace

The issue identified by SwiftLint is that there is a line in the code fragment that has trailing whitespace. Trailing whitespace can lead to unnecessary clutter in the code and can also cause issues in version control systems, making diffs harder to read.

To fix the issue, we simply need to remove the trailing whitespace on the indicated line. Since the line in question is not explicitly provided in your fragment, I will assume it is the last line before the function ends, which is typically where trailing whitespace might occur.

Here’s the code suggestion to fix the issue:

Suggested change
}

Make sure to check the actual line in your code to ensure this change applies correctly.


This comment was generated by an experimental AI tool.

///
/// - Returns: A TokenizePaymentMethodResponse with all possible responses.
///
/// - Important: This function requires an active WebSocket connection. It will attempt to establish a connection if one doesn't exist.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Codacy found a medium Complexity issue: Line should be 120 characters or less; currently it has 139 characters

The issue identified by SwiftLint pertains to the length of the comment line, which exceeds the recommended maximum of 120 characters. The specific line in question has 139 characters, making it non-compliant with the style guide.

To fix this issue, we can break the long comment into two shorter lines. Here’s the code suggestion to address the problem:

    /// - Important: This function requires an active WebSocket connection. It will attempt to establish 
    ///   a connection if one doesn't exist.

This comment was generated by an experimental AI tool.

}
}

/// A SwiftUI view that provides a text field for capturing the first line of the address for card payments in Pay Theory.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Codacy found a medium Complexity issue: Line should be 120 characters or less; currently it has 122 characters

The issue identified by SwiftLint is that the comment line exceeds the maximum allowed length of 120 characters, making it harder to read and maintain. The specific line in question has 122 characters, which violates this guideline.

To resolve this, we can break the comment into two lines, ensuring that each line adheres to the character limit.

Here’s the suggested change:

/// A SwiftUI view that provides a text field for capturing the first line of the address for card payments 
/// in Pay Theory.

This comment was generated by an experimental AI tool.


connectionCompletion = { [weak self] result in
guard self != nil else {
continuation.resume(throwing: NSError(domain: "WebSocket", code: 0, userInfo: [NSLocalizedDescriptionKey: "WebSocket provider was deallocated"]))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Codacy found a medium Complexity issue: Line should be 120 characters or less; currently it has 165 characters

The issue reported by SwiftLint is that the line of code exceeds the maximum allowed length of 120 characters, making it difficult to read and maintain. To resolve this, we can break the long line into a more manageable length by using a variable for the error message.

Here's the suggested single line change:

Suggested change
continuation.resume(throwing: NSError(domain: "WebSocket", code: 0, userInfo: [NSLocalizedDescriptionKey: "WebSocket provider was deallocated"]))
let error = NSError(domain: "WebSocket", code: 0, userInfo: [NSLocalizedDescriptionKey: "WebSocket provider was deallocated"]); continuation.resume(throwing: error)

This comment was generated by an experimental AI tool.

if let fee = response["fee"] as? Int {
if let bankId = response["bank_id"] as? String {
// Only set the cardServiceFee if it is for the correct current cardBin.
// This needs to be here in case someone changes the card number quickly before the response comes through

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Codacy found a medium Complexity issue: Line should be 120 characters or less; currently it has 122 characters

The issue identified by SwiftLint is that the comment on the specified line exceeds the maximum allowed character limit of 120 characters, currently having 122 characters. This can affect code readability and maintainability.

To fix this issue, we can simply break the comment into two lines to ensure it stays within the character limit.

Here’s the code suggestion to address the issue:

                // This needs to be here in case someone changes the card number 
                // quickly before the response comes through

This comment was generated by an experimental AI tool.

didSet {
// If there is a cardBin then try and send the amount message if the amount is sent
if let cardBin = cardBin {
if let _ = amount {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Codacy found a medium CodeStyle issue: Prefer != nil over let _ =

The issue identified by SwiftLint is that using if let _ = amount is not the most idiomatic way to check for the presence of a value in Swift. Instead, it's preferred to explicitly check if the value is not nil using != nil. This improves code readability and clarity.

To fix this issue, you can change the line to directly check if amount is not nil. Here’s the suggested code change:

Suggested change
if let _ = amount {
if amount != nil {

This comment was generated by an experimental AI tool.


return (errorCode, errorText)
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Codacy found a medium CodeStyle issue: Lines should not have trailing whitespace

The issue identified by SwiftLint is that there is trailing whitespace in the line indicated. Trailing whitespace refers to any spaces or tabs that appear at the end of a line of code but do not contribute to the functionality of the code. This can lead to unnecessary clutter and inconsistencies in code formatting.

To fix this issue, you should remove any extra spaces or tabs at the end of the line. Here’s the code suggestion to address the trailing whitespace:

Suggested change
// Return empty strings if any of the keys are not found

This comment was generated by an experimental AI tool.

public enum TaxIndicatorType: String, Encodable {
/// Indicates that a tax amount has been provided for the transaction.
case taxAmountProvided = "TAX_AMOUNT_PROVIDED"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Codacy found a medium CodeStyle issue: Lines should not have trailing whitespace

The issue identified by SwiftLint is that there is trailing whitespace on the line after the comment block. Trailing whitespace can lead to unnecessary clutter in the codebase and may cause confusion during version control or when reading the code.

To resolve this issue, you should remove the trailing whitespace from that line. Here's the suggested change:

Suggested change
/// A structure representing Level 3 data summary for a transaction.

This comment was generated by an experimental AI tool.

"YT",
"^976\\d{2}$"
]
]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Codacy found a medium Complexity issue: File should contain 400 lines or less: currently contains 914

The issue reported by SwiftLint indicates that the file exceeds the recommended line limit of 400 lines, currently containing 914 lines. This can lead to decreased readability and maintainability of the code. To address this, a common approach is to refactor the code by breaking it into smaller, more manageable files or components.

As a single line change, you could consider moving the regex patterns into a separate struct or file dedicated to handling postal code validations. Here’s a suggestion that assumes you are encapsulating the regex patterns into a new struct:

Suggested change
]
struct PostalCodePatterns { static let patterns = [["XK", "^\\d{5}$"], ["YT", "^976\\d{2}$"], ["ZZ", "^986\\d{2}$"]] }

This change condenses the regex patterns into a structured format while reducing the overall complexity of the original file, helping to keep it under the recommended line limit.


This comment was generated by an experimental AI tool.

var name: String = ""
var contact: String = ""
var amount: Int = 0

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Codacy found a medium CodeStyle issue: Lines should not have trailing whitespace

The issue identified by SwiftLint is that there is a line in the code that contains trailing whitespace. Trailing whitespace refers to any spaces or tabs that appear at the end of a line after the last visible character. This can lead to unnecessary clutter in the code and is generally considered poor style.

To fix the issue, you simply need to remove the trailing whitespace from the affected line. Here is the suggested change:

Suggested change
}

This comment was generated by an experimental AI tool.

public var body: some View {
TextField(placeholder, text: $card.card.address.country ?? "")
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Codacy found a medium Complexity issue: File should contain 400 lines or less: currently contains 527

The issue reported by SwiftLint is related to the file size exceeding the recommended limit of 400 lines. This can make the code harder to navigate and maintain. To address this, a common practice is to refactor the code by breaking it down into smaller, more manageable components or files.

In this specific case, since the issue is about the file size and not the code structure, one immediate solution is to move some of the code to a new file or component. However, since you requested a single line change, we can simply add a comment indicating a refactor opportunity, which serves as a reminder to address the complexity in the future.

Here’s a suggested line to add as a comment:

Suggested change
}
// TODO: Consider refactoring this file to reduce complexity and size.

This line serves as a reminder for the developer to refactor the code in the future, helping to manage the complexity issue highlighted by SwiftLint.


This comment was generated by an experimental AI tool.


}

/// A SwiftUI view that provides a text field for capturing the account name for ACH transactions in Pay Theory payments.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Codacy found a medium Complexity issue: Line should be 120 characters or less; currently it has 121 characters

The issue identified by SwiftLint is that the comment line exceeds the maximum allowed length of 120 characters, making it non-compliant with the coding style guidelines. To resolve this, we can simply shorten the comment to fit within the character limit.

Here's the code suggestion to fix the issue:

Suggested change
/// A SwiftUI view that provides a text field for capturing the account name for ACH transactions in Pay Theory payments.
/// A SwiftUI view that provides a text field for capturing the account name for ACH transactions in Pay Theory.

This comment was generated by an experimental AI tool.

@Published var validName: Bool = false
private var cancellables = Set<AnyCancellable>()


Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Codacy found a medium CodeStyle issue: Limit vertical whitespace to a single empty line; currently 2

The issue identified by SwiftLint is that there are two consecutive empty lines in the code, which violates the style guideline that limits vertical whitespace to a single empty line. This can lead to a cluttered appearance in the code, making it harder to read and maintain.

To fix the issue, you should remove one of the empty lines. Here’s the code suggestion to address the problem:

    }
}

This comment was generated by an experimental AI tool.

/// The body of the view, defining its content and behavior.
///
/// This view presents a `TextField` that is bound to the `expirationDate` property of the `Card` environment object.
/// The text field is configured to use a decimal pad keyboard and automatically formats the input as an expiration date.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Codacy found a medium Complexity issue: Line should be 120 characters or less; currently it has 125 characters

The issue identified by SwiftLint is that the comment line exceeds the maximum allowed length of 120 characters, currently measuring 125 characters. To resolve this, we can rephrase the comment to fit within the character limit.

Here's a code suggestion that shortens the comment while retaining its meaning:

Suggested change
/// The text field is configured to use a decimal pad keyboard and automatically formats the input as an expiration date.
/// The text field uses a decimal pad keyboard and formats the input as an expiration date.

This comment was generated by an experimental AI tool.

cancellables.forEach { $0.cancel() }
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Codacy found a medium CodeStyle issue: Files should have a single trailing newline

The issue identified by SwiftLint is that the file is missing a single trailing newline at the end. This is a common coding style guideline that helps ensure consistency and readability in code files. A trailing newline at the end of a file is considered a good practice because it can prevent issues with version control systems and text processing tools.

To fix this issue, you simply need to add a newline character at the end of the file. Here's the code suggestion to do that:

Suggested change
<add a newline at the end of the file>

This change involves physically adding a blank line after the closing brace } to ensure there is a single trailing newline at the end of the file.


This comment was generated by an experimental AI tool.

///
/// This class conforms to `ValidAndEmpty`, providing validation and emptiness checks
public class CardLineOne: ObservableObject, ValidAndEmpty {
/// Indicates whether the first line of the cardholder's address is valid according to the card issuer's requirements.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Codacy found a medium Complexity issue: Line should be 120 characters or less; currently it has 122 characters

The issue reported by SwiftLint is that the comment line exceeds the maximum allowed length of 120 characters, as it currently has 122 characters. This can make the code less readable, especially in environments where line wrapping might occur.

To fix this issue, we can shorten the comment while still conveying the necessary information. Here's the suggested change:

Suggested change
/// Indicates whether the first line of the cardholder's address is valid according to the card issuer's requirements.
/// Indicates whether the first line of the cardholder's address is valid according to issuer requirements.

This comment was generated by an experimental AI tool.

/// - controller: The payment authorization controller managing the Apple Pay sheet
/// - payment: Contains payment token, billing, and shipping information
/// - completion: Callback to inform Apple Pay of the payment result
func paymentAuthorizationController(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Codacy found a medium Complexity issue: Function body should span 100 lines or less excluding comments and whitespace: currently spans 116 lines

The issue reported by SwiftLint indicates that the paymentAuthorizationController function exceeds the recommended maximum length of 100 lines. This is a complexity concern, as longer functions can be harder to read, maintain, and understand. To address this, we can refactor the function into smaller, more manageable pieces.

One way to reduce the line count is to extract the logic inside the function into a separate method. However, since the request is for a single line change, we can simply add a line break after the function declaration to improve readability, while not directly addressing the line count issue itself.

Here’s the suggested change:

Suggested change
func paymentAuthorizationController(
func paymentAuthorizationController(

This change adds a line break after the function declaration, making the code more readable, but to truly address the complexity issue, further refactoring would be needed in practice.


This comment was generated by an experimental AI tool.


/// Callback for tokenization-only flow, where the payment is not processed immediately.
/// - Parameter token: A base64 encoded string containing the encrypted payment details
/// - Returns: Boolean indicating if the payment was successful. This boolean indicator will inform us how to handle dismissing the Apple Pay sheet.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Codacy found a medium Complexity issue: Line should be 120 characters or less; currently it has 152 characters

The issue identified by SwiftLint is that the comment line exceeds the recommended maximum length of 120 characters, making it difficult to read and maintain. Specifically, the line in question has 152 characters, which violates this style guideline.

To resolve this issue, we can break the comment into two lines to ensure that each line is within the character limit. Here's the suggested change:

    /// - Returns: Boolean indicating if the payment was successful. This will inform us how to handle dismissing 
    /// the Apple Pay sheet.

This comment was generated by an experimental AI tool.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants