Skip to content

Commit

Permalink
chore Fix all warnings (#1468)
Browse files Browse the repository at this point in the history
## Summary
- Using `Void?` as associated key type as described
[here](https://github.com/atrick/swift-evolution/blob/diagnose-implicit-raw-bitwise/proposals/nnnn-implicit-raw-bitwise-conversion.md#workarounds-for-common-cases)
- ~Using `PKShippingContactEditingMode.available` instead of `.enabled`
because of deprecation~
  - Actually this is only available/deprecated using Xcode 15 🤷 
- Increasing linting file-line-limit-warning to 500
- Splitting up function/class bodies
- Reducing `swiftlint:disable`
  • Loading branch information
goergisn authored Nov 28, 2023
2 parents ed9c64f + a1d3bc1 commit 4bbce20
Show file tree
Hide file tree
Showing 30 changed files with 160 additions and 110 deletions.
3 changes: 3 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ line_length:
ignores_function_declarations: true
ignores_urls: true
warning: 140

file_length:
warning: 500
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ open class AbstractPersonalInformationComponent: PaymentComponent, PresentableCo
lastNameItem?.value = $0.lastName
}
shopperInformation.emailAddress.map { emailItem?.value = $0 }
shopperInformation.telephoneNumber.map { phoneItem?.value = $0 }
shopperInformation.phoneNumber.map { phoneItem?.value = $0.value }
shopperInformation.billingAddress.map { addressItem?.value = $0 }
shopperInformation.deliveryAddress.map { deliveryAddressItem?.value = $0 }
}
Expand Down
8 changes: 4 additions & 4 deletions Adyen/Core/Core Protocols/Component.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2022 Adyen N.V.
// Copyright (c) 2023 Adyen N.V.
//
// This file is open source and available under the MIT license. See the LICENSE file for more info.
//
Expand Down Expand Up @@ -65,9 +65,9 @@ public extension Component {
}

private enum AssociatedKeys {
internal static var isDropIn = "isDropInObject"
internal static var isDropIn: Void?

internal static var environment = "environmentObject"
internal static var environment: Void?

internal static var clientKey = "clientKeyObject"
internal static var clientKey: Void?
}
6 changes: 3 additions & 3 deletions Adyen/Core/Core Protocols/PaymentAwareComponent.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2022 Adyen N.V.
// Copyright (c) 2023 Adyen N.V.
//
// This file is open source and available under the MIT license. See the LICENSE file for more info.
//
Expand Down Expand Up @@ -37,7 +37,7 @@ extension PartialPaymentOrderAware {

private enum AssociatedKeys {

internal static var payment = "paymentObject"
internal static var payment: Void?

internal static var order = "orderObject"
internal static var order: Void?
}
6 changes: 3 additions & 3 deletions Adyen/Core/Models/CardType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public enum CardType: RawRepresentable, Codable, Equatable, Hashable {

/// Korea Cyber Payment
case kcp

/// Korean local card
case koreanLocalCard

Expand Down Expand Up @@ -141,7 +141,7 @@ public enum CardType: RawRepresentable, Codable, Equatable, Hashable {
/// Fallback option for any other scheme name
case other(named: String)

// swiftlint:disable cyclomatic_complexity
// swiftlint:disable cyclomatic_complexity function_body_length
public init(rawValue: String) {
switch rawValue {
case "accel": self = .accel
Expand Down Expand Up @@ -292,7 +292,7 @@ public enum CardType: RawRepresentable, Codable, Equatable, Hashable {
case let .other(name): return name.replacingOccurrences(of: "_", with: " ")
}
}
// swiftlint:enable cyclomatic_complexity
// swiftlint:enable cyclomatic_complexity function_body_length
}

extension CardType {
Expand Down
7 changes: 5 additions & 2 deletions Adyen/Core/Payment Methods/Abstract/PaymentMethodType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public enum PaymentMethodType: RawRepresentable, Hashable, Codable {
case other(String)

// swiftlint:disable cyclomatic_complexity function_body_length

public init?(rawValue: String) {
switch rawValue {
case "card": self = .card
Expand Down Expand Up @@ -122,7 +122,7 @@ public enum PaymentMethodType: RawRepresentable, Hashable, Codable {
default: self = .other(rawValue)
}
}

public var rawValue: String {
switch self {
case .card: return "card"
Expand Down Expand Up @@ -180,6 +180,9 @@ public enum PaymentMethodType: RawRepresentable, Hashable, Codable {
case let .other(value): return value
}
}
}

extension PaymentMethodType {

/// The brand name of the card type
///
Expand Down
2 changes: 1 addition & 1 deletion Adyen/Helpers/UIViewAnimation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import UIKit

private enum AssociatedKeys {
internal static var animations = "animations"
internal static var animations: Void?
}

@_spi(AdyenInternal)
Expand Down
34 changes: 29 additions & 5 deletions Adyen/UI/Form/Items/Phone Number/FormPhoneNumberItem.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2022 Adyen N.V.
// Copyright (c) 2023 Adyen N.V.
//
// This file is open source and available under the MIT license. See the LICENSE file for more info.
//
Expand Down Expand Up @@ -31,11 +31,15 @@ public final class FormPhoneNumberItem: FormTextItem {
selectableValues: [PhoneExtensionPickerItem],
style: FormTextItemStyle,
localizationParameters: LocalizationParameters? = nil) {
// swiftlint:disable:next line_length
let preselectedValue = selectableValues.first(where: { $0.element.value == phoneNumber?.callingCode }) ?? selectableValues.first(where: { $0.identifier == Locale.current.regionCode }) ?? selectableValues[0]

phonePrefixItem = FormPhoneExtensionPickerItem(preselectedValue: preselectedValue, selectableValues: selectableValues, style: style)

phonePrefixItem = FormPhoneExtensionPickerItem(
preselectedValue: selectableValues.preselectedPhoneNumberPrefix(for: phoneNumber),
selectableValues: selectableValues,
style: style
)

super.init(style: style)

phonePrefixItem.identifier = ViewIdentifierBuilder.build(scopeInstance: self, postfix: "phoneExtensionPickerItem")
value = phoneNumber?.value ?? ""

Expand All @@ -50,5 +54,25 @@ public final class FormPhoneNumberItem: FormTextItem {
override public func build(with builder: FormItemViewBuilder) -> AnyFormItemView {
builder.build(with: self)
}
}

private extension [PhoneExtensionPickerItem] {

func preselectedPhoneNumberPrefix(for phoneNumber: PhoneNumber?) -> PhoneExtensionPickerItem {

if let matchingCallingCode = first(where: { $0.element.value == phoneNumber?.callingCode }) {
return matchingCallingCode
}

if let matchingLocaleRegion = first(where: { $0.identifier == Locale.current.regionCode }) {
return matchingLocaleRegion
}

if let firstSelectableValue = first {
return firstSelectableValue
}

AdyenAssertion.assertionFailure(message: "Empty list of selectableValues provided")
return .init(identifier: "", element: .init(value: "+1", countryCode: "US"))
}
}
2 changes: 1 addition & 1 deletion Adyen/UI/List/ListItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public class ListItem: FormItem {

private func setLoading(_ isLoading: Bool) {
guard let loadingHandler else {
assertionFailure("No loadingHandler provided")
AdyenAssertion.assertionFailure(message: "No loadingHandler provided")
return
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ private extension AddressLookupViewController {
}
}

internal extension AddressLookupViewController.ViewModel {
extension AddressLookupViewController.ViewModel {

func buildAddressInputFormViewModel(
internal func buildAddressInputFormViewModel(
with prefillAddress: PostalAddress?
) -> AddressInputFormViewController.ViewModel {

Expand All @@ -96,7 +96,7 @@ internal extension AddressLookupViewController.ViewModel {
)
}

func buildAddressSearchViewModel(
internal func buildAddressSearchViewModel(
presentationHandler: @escaping (UIViewController) -> Void
) -> AddressLookupSearchViewController.ViewModel {

Expand Down
2 changes: 0 additions & 2 deletions Adyen/Utilities/External/AllCountriesPhoneExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import Foundation

// swiftlint:disable file_length
internal let allCountriesPhoneExtensions: [String: String] = [

"AF": "+93",
Expand Down Expand Up @@ -492,4 +491,3 @@ internal let allCountriesPhoneExtensions: [String: String] = [
"VI": "+1 340"

]
// swiftlint:enable file_length
4 changes: 2 additions & 2 deletions Adyen/Utilities/Observable/AdyenObserver.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2022 Adyen N.V.
// Copyright (c) 2023 Adyen N.V.
//
// This file is open source and available under the MIT license. See the LICENSE file for more info.
//
Expand Down Expand Up @@ -160,6 +160,6 @@ public extension AdyenObserver {
private enum AssociatedKeys {

/// The observation manager associated with the object.
public static var observationManager = "observationManager"
public static var observationManager: Void?

}
29 changes: 20 additions & 9 deletions AdyenCard/Components/Card/CardViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,11 @@ internal class CardViewController: FormViewController {

updateBillingAddressOptionalStatus(brands: brands)
}
}

// MARK: - Private methods

extension CardViewController {

private func updateBillingAddressOptionalStatus(brands: [CardBrand]) {
let isOptional = configuration.billingAddress.isOptional(for: brands.map(\.type))
Expand Down Expand Up @@ -270,33 +275,39 @@ internal class CardViewController: FormViewController {
append(items.storeDetailsItem)
append(FormSpacerItem())
}

if let billingAddressItem = billingAddressItem(for: configuration.billingAddress.mode) {
append(billingAddressItem)
}

switch configuration.billingAddress.mode {
append(FormSpacerItem())
append(items.button)
append(FormSpacerItem(numberOfSpaces: 2))
}

private func billingAddressItem(for billingAddressMode: CardComponent.AddressFormType) -> FormItem? {
switch billingAddressMode {
case let .lookup(provider):
let item = items.billingAddressPickerItem
item.selectionHandler = { [weak cardDelegate, weak provider] in
guard let provider else { return }
cardDelegate?.didSelectAddressPicker(lookupProvider: provider)
}
append(item)
return item

case .full:
let item = items.billingAddressPickerItem
item.selectionHandler = { [weak cardDelegate] in
cardDelegate?.didSelectAddressPicker(lookupProvider: nil)
}
append(item)
return item

case .postalCode:
append(items.postalCodeItem)
return items.postalCodeItem

case .none:
break
return nil
}

append(FormSpacerItem())
append(items.button)
append(FormSpacerItem(numberOfSpaces: 2))
}

private func prefill() {
Expand Down
7 changes: 5 additions & 2 deletions AdyenDropIn/Utilities/ComponentManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,11 @@ internal final class ComponentManager {

private func component(for paymentMethod: PaymentMethod) -> PaymentComponent? {
guard isAllowed(paymentMethod) else {
// swiftlint:disable:next line_length
AdyenAssertion.assertionFailure(message: "For voucher payment methods like \(paymentMethod.name) it is required to add a suitable text for the key NSPhotoLibraryAddUsageDescription in the Application Info.plist, to enable the shopper to save the voucher to their photo library.")
AdyenAssertion.assertionFailure(message: """
For voucher payment methods like \(paymentMethod.name) it is required to add a suitable \
text for the key NSPhotoLibraryAddUsageDescription in the Application Info.plist, to enable \
the shopper to save the voucher to their photo library.
""")
return nil
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (c) 2022 Adyen N.V.
// Copyright (c) 2023 Adyen N.V.
//
// This file is open source and available under the MIT license. See the LICENSE file for more info.
//
Expand Down Expand Up @@ -69,8 +69,9 @@ import Foundation

private static func assertWeChatPayAppSchemeConfigured() {
guard Bundle.main.adyen.isSchemeConfigured("weixin") else {
// swiftlint:disable:next line_length
return AdyenAssertion.assertionFailure(message: "weixin:// scheme must be added to Info.plist under LSApplicationQueriesSchemes key.")
return AdyenAssertion.assertionFailure(message: """
weixin:// scheme must be added to Info.plist under LSApplicationQueriesSchemes key.
""")
}
}

Expand Down
4 changes: 2 additions & 2 deletions Demo/Common/Configuration/ConfigurationView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,10 @@ private struct ListItemView<T: Hashable>: View {
}.tag(viewModel.tag)
}

fileprivate struct ViewModel<T: Hashable> {
fileprivate struct ViewModel<Tag: Hashable> {
let title: String
let subtitle: String
let tag: T
let tag: Tag
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Adyen
import AdyenActions
import AdyenComponents

internal final class InstantPaymentComponentAdvancedFlowExample: InitialDataAdvancedFlowProtocol {
internal final class InstantPaymentComponentAdvancedFlow: InitialDataAdvancedFlowProtocol {

// MARK: - Properties

Expand Down Expand Up @@ -127,7 +127,7 @@ internal final class InstantPaymentComponentAdvancedFlowExample: InitialDataAdva

}

extension InstantPaymentComponentAdvancedFlowExample: PaymentComponentDelegate {
extension InstantPaymentComponentAdvancedFlow: PaymentComponentDelegate {

internal func didSubmit(_ data: PaymentComponentData, from component: PaymentComponent) {
presenter?.showLoadingIndicator()
Expand All @@ -144,7 +144,7 @@ extension InstantPaymentComponentAdvancedFlowExample: PaymentComponentDelegate {

}

extension InstantPaymentComponentAdvancedFlowExample: ActionComponentDelegate {
extension InstantPaymentComponentAdvancedFlow: ActionComponentDelegate {

internal func didFail(with error: Error, from component: ActionComponent) {
finish(with: error)
Expand All @@ -167,14 +167,14 @@ extension InstantPaymentComponentAdvancedFlowExample: ActionComponentDelegate {
}
}

extension InstantPaymentComponentAdvancedFlowExample: PresentationDelegate {
extension InstantPaymentComponentAdvancedFlow: PresentationDelegate {
internal func present(component: PresentableComponent) {
let componentViewController = viewController(for: component)
presenter?.present(viewController: componentViewController, completion: nil)
}
}

private extension InstantPaymentComponentAdvancedFlowExample {
private extension InstantPaymentComponentAdvancedFlow {

private func viewController(for component: PresentableComponent) -> UIViewController {
guard component.requiresModalPresentation else {
Expand Down
8 changes: 5 additions & 3 deletions Demo/Configuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,11 @@ internal struct DemoAppSettings: Codable {
}
let defaultInstallmentOptions = InstallmentOptions(monthValues: [2, 3, 4], includesRevolving: true)
let visaInstallmentOptions = InstallmentOptions(monthValues: [3, 4, 6], includesRevolving: false)
return InstallmentConfiguration(cardBasedOptions: [.visa: visaInstallmentOptions],
defaultOptions: defaultInstallmentOptions,
showInstallmentAmount: cardSettings.showsInstallmentAmount)
return InstallmentConfiguration(
cardBasedOptions: [.visa: visaInstallmentOptions],
defaultOptions: defaultInstallmentOptions,
showInstallmentAmount: cardSettings.showsInstallmentAmount
)
}

internal static let defaultConfiguration = DemoAppSettings(
Expand Down
Loading

0 comments on commit 4bbce20

Please sign in to comment.