<commit_before>//
//  EurofurenceApplicationBuilder.swift
//  Eurofurence
//
//  Created by <NAME> on 22/01/2018.
//  Copyright © 2018 Eurofurence. All rights reserved.
//

import Foundation

class EurofurenceApplicationBuilder {

    private var userPreferences: UserPreferences
    private var dataStore: EurofurenceDataStore
    private var remoteNotificationsTokenRegistration: RemoteNotificationsTokenRegistration
    private var pushPermissionsRequester: PushPermissionsRequester
    private var pushPermissionsStateProviding: PushPermissionsStateProviding
    private var clock: Clock
    private var credentialStore: CredentialStore
    private var loginAPI: LoginAPI
    private var privateMessagesAPI: PrivateMessagesAPI
    private var syncAPI: SyncAPI
    private var dateDistanceCalculator: DateDistanceCalculator
    private var conventionStartDateRepository: ConventionStartDateRepository
    private var significantTimeChangeEventSource: SignificantTimeChangeEventSource
    private var timeIntervalForUpcomingEventsSinceNow: TimeInterval
    private var imageAPI: ImageAPI
    private var imageRepository: ImageRepository

    init() {
        struct DummyUserPreferences: UserPreferences {
            var refreshStoreOnLaunch: Bool = true
        }

        struct DummyEurofurenceDataStore: EurofurenceDataStore {
            func performTransaction(_ block: @escaping (EurofurenceDataStoreTransaction) -> Void) {

            }

            func resolveContentsState(completionHandler: @escaping (EurofurenceDataStoreContentsState) -> Void) {
                completionHandler(.present)
            }
            func fetchKnowledgeGroups(completionHandler: ([KnowledgeGroup2]?) -> Void) {
                completionHandler(nil)
            }
        }

        struct DummyImageAPI: ImageAPI {
            func fetchImage(identifier: String, completionHandler: @escaping (Data?) -> Void) {

            }
        }

        struct DummyImageRepository: ImageRepository {
            func save(_ image: ImageEntity) {

            }
        }

        userPreferences = DummyUserPreferences()
        dataStore = DummyEurofurenceDataStore()

        let jsonSession = URLSessionBasedJSONSession()

        let fcmRegistration = EurofurenceFCMDeviceRegistration(JSONSession: jsonSession)
        remoteNotificationsTokenRegistration = FirebaseRemoteNotificationsTokenRegistration(buildConfiguration: PreprocessorBuildConfigurationProviding(),
                                                                                            appVersion: BundleAppVersionProviding(),
                                                                                            firebaseAdapter: FirebaseMessagingAdapter(),
                                                                                            fcmRegistration: fcmRegistration)

        pushPermissionsRequester = ApplicationPushPermissionsRequester()
        pushPermissionsStateProviding = UserDefaultsWitnessedSystemPushPermissionsRequest()
        clock = SystemClock()
        credentialStore = KeychainCredentialStore()
        loginAPI = V2LoginAPI(jsonSession: jsonSession)
        privateMessagesAPI = V2PrivateMessagesAPI(jsonSession: jsonSession)
        syncAPI = V2SyncAPI(jsonSession: jsonSession)
        imageAPI = DummyImageAPI()
        dateDistanceCalculator = FoundationDateDistanceCalculator()
        conventionStartDateRepository = EF24StartDateRepository()
        significantTimeChangeEventSource = ApplicationSignificantTimeChangeEventSource.shared
        timeIntervalForUpcomingEventsSinceNow = 3600
        imageRepository = DummyImageRepository()
    }

    @discardableResult
    func with(_ userPreferences: UserPreferences) -> EurofurenceApplicationBuilder {
        self.userPreferences = userPreferences
        return self
    }

    @discardableResult
    func with(_ dataStore: EurofurenceDataStore) -> EurofurenceApplicationBuilder {
        self.dataStore = dataStore
        return self
    }

    @discardableResult
    func with(_ remoteNotificationsTokenRegistration: RemoteNotificationsTokenRegistration) -> EurofurenceApplicationBuilder {
        self.remoteNotificationsTokenRegistration = remoteNotificationsTokenRegistration
        return self
    }

    @discardableResult
    func with(_ pushPermissionsRequester: PushPermissionsRequester) -> EurofurenceApplicationBuilder {
        self.pushPermissionsRequester = pushPermissionsRequester
        return self
    }

    @discardableResult
    func with(_ pushPermissionsStateProviding: PushPermissionsStateProviding) -> EurofurenceApplicationBuilder {
        self.pushPermissionsStateProviding = pushPermissionsStateProviding
        return self
    }

    @discardableResult
    func with(_ clock: Clock) -> EurofurenceApplicationBuilder {
        self.clock = clock
        return self
    }

    @discardableResult
    func with(_ credentialStore: CredentialStore) -> EurofurenceApplicationBuilder {
        self.credentialStore = credentialStore
        return self
    }

    @discardableResult
    func with(_ loginAPI: LoginAPI) -> EurofurenceApplicationBuilder {
        self.loginAPI = loginAPI
        return self
    }

    @discardableResult
    func with(_ privateMessagesAPI: PrivateMessagesAPI) -> EurofurenceApplicationBuilder {
        self.privateMessagesAPI = privateMessagesAPI
        return self
    }

    @discardableResult
    func with(_ syncAPI: SyncAPI) -> EurofurenceApplicationBuilder {
        self.syncAPI = syncAPI
        return self
    }

    @discardableResult
    func with(_ dateDistanceCalculator: DateDistanceCalculator) -> EurofurenceApplicationBuilder {
        self.dateDistanceCalculator = dateDistanceCalculator
        return self
    }

    @discardableResult
    func with(_ conventionStartDateRepository: ConventionStartDateRepository) -> EurofurenceApplicationBuilder {
        self.conventionStartDateRepository = conventionStartDateRepository
        return self
    }

    @discardableResult
    func with(_ significantTimeChangeEventSource: SignificantTimeChangeEventSource) -> EurofurenceApplicationBuilder {
        self.significantTimeChangeEventSource = significantTimeChangeEventSource
        return self
    }

    @discardableResult
    func with(timeIntervalForUpcomingEventsSinceNow: TimeInterval) -> EurofurenceApplicationBuilder {
        self.timeIntervalForUpcomingEventsSinceNow = timeIntervalForUpcomingEventsSinceNow
        return self
    }

    @discardableResult
    func with(_ imageAPI: ImageAPI) -> EurofurenceApplicationBuilder {
        self.imageAPI = imageAPI
        return self
    }

    @discardableResult
    func with(_ imageRepository: ImageRepository) -> EurofurenceApplicationBuilder {
        self.imageRepository = imageRepository
        return self
    }

    func build() -> EurofurenceApplicationProtocol {
        return EurofurenceApplication(userPreferences: userPreferences,
                                      dataStore: dataStore,
                                      remoteNotificationsTokenRegistration: remoteNotificationsTokenRegistration,
                                      pushPermissionsRequester: pushPermissionsRequester,
                                      pushPermissionsStateProviding: pushPermissionsStateProviding,
                                      clock: clock,
                                      credentialStore: credentialStore,
                                      loginAPI: loginAPI,
                                      privateMessagesAPI: privateMessagesAPI,
                                      syncAPI: syncAPI,
                                      imageAPI: imageAPI,
                                      dateDistanceCalculator: dateDistanceCalculator,
                                      conventionStartDateRepository: conventionStartDateRepository,
                                      significantTimeChangeEventSource: significantTimeChangeEventSource,
                                      timeIntervalForUpcomingEventsSinceNow: timeIntervalForUpcomingEventsSinceNow,
                                      imageRepository: imageRepository)
    }

}
<commit_msg>Make dummy image service always fail<commit_after>//
//  EurofurenceApplicationBuilder.swift
//  Eurofurence
//
//  Created by <NAME> on 22/01/2018.
//  Copyright © 2018 Eurofurence. All rights reserved.
//

import Foundation

class EurofurenceApplicationBuilder {

    private var userPreferences: UserPreferences
    private var dataStore: EurofurenceDataStore
    private var remoteNotificationsTokenRegistration: RemoteNotificationsTokenRegistration
    private var pushPermissionsRequester: PushPermissionsRequester
    private var pushPermissionsStateProviding: PushPermissionsStateProviding
    private var clock: Clock
    private var credentialStore: CredentialStore
    private var loginAPI: LoginAPI
    private var privateMessagesAPI: PrivateMessagesAPI
    private var syncAPI: SyncAPI
    private var dateDistanceCalculator: DateDistanceCalculator
    private var conventionStartDateRepository: ConventionStartDateRepository
    private var significantTimeChangeEventSource: SignificantTimeChangeEventSource
    private var timeIntervalForUpcomingEventsSinceNow: TimeInterval
    private var imageAPI: ImageAPI
    private var imageRepository: ImageRepository

    init() {
        struct DummyUserPreferences: UserPreferences {
            var refreshStoreOnLaunch: Bool = true
        }

        struct DummyEurofurenceDataStore: EurofurenceDataStore {
            func performTransaction(_ block: @escaping (EurofurenceDataStoreTransaction) -> Void) {

            }

            func resolveContentsState(completionHandler: @escaping (EurofurenceDataStoreContentsState) -> Void) {
                completionHandler(.present)
            }
            func fetchKnowledgeGroups(completionHandler: ([KnowledgeGroup2]?) -> Void) {
                completionHandler(nil)
            }
        }

        struct DummyImageAPI: ImageAPI {
            func fetchImage(identifier: String, completionHandler: @escaping (Data?) -> Void) {
                completionHandler(nil)
            }
        }

        struct DummyImageRepository: ImageRepository {
            func save(_ image: ImageEntity) {

            }
        }

        userPreferences = DummyUserPreferences()
        dataStore = DummyEurofurenceDataStore()

        let jsonSession = URLSessionBasedJSONSession()

        let fcmRegistration = EurofurenceFCMDeviceRegistration(JSONSession: jsonSession)
        remoteNotificationsTokenRegistration = FirebaseRemoteNotificationsTokenRegistration(buildConfiguration: PreprocessorBuildConfigurationProviding(),
                                                                                            appVersion: BundleAppVersionProviding(),
                                                                                            firebaseAdapter: FirebaseMessagingAdapter(),
                                                                                            fcmRegistration: fcmRegistration)

        pushPermissionsRequester = ApplicationPushPermissionsRequester()
        pushPermissionsStateProviding = UserDefaultsWitnessedSystemPushPermissionsRequest()
        clock = SystemClock()
        credentialStore = KeychainCredentialStore()
        loginAPI = V2LoginAPI(jsonSession: jsonSession)
        privateMessagesAPI = V2PrivateMessagesAPI(jsonSession: jsonSession)
        syncAPI = V2SyncAPI(jsonSession: jsonSession)
        imageAPI = DummyImageAPI()
        dateDistanceCalculator = FoundationDateDistanceCalculator()
        conventionStartDateRepository = EF24StartDateRepository()
        significantTimeChangeEventSource = ApplicationSignificantTimeChangeEventSource.shared
        timeIntervalForUpcomingEventsSinceNow = 3600
        imageRepository = DummyImageRepository()
    }

    @discardableResult
    func with(_ userPreferences: UserPreferences) -> EurofurenceApplicationBuilder {
        self.userPreferences = userPreferences
        return self
    }

    @discardableResult
    func with(_ dataStore: EurofurenceDataStore) -> EurofurenceApplicationBuilder {
        self.dataStore = dataStore
        return self
    }

    @discardableResult
    func with(_ remoteNotificationsTokenRegistration: RemoteNotificationsTokenRegistration) -> EurofurenceApplicationBuilder {
        self.remoteNotificationsTokenRegistration = remoteNotificationsTokenRegistration
        return self
    }

    @discardableResult
    func with(_ pushPermissionsRequester: PushPermissionsRequester) -> EurofurenceApplicationBuilder {
        self.pushPermissionsRequester = pushPermissionsRequester
        return self
    }

    @discardableResult
    func with(_ pushPermissionsStateProviding: PushPermissionsStateProviding) -> EurofurenceApplicationBuilder {
        self.pushPermissionsStateProviding = pushPermissionsStateProviding
        return self
    }

    @discardableResult
    func with(_ clock: Clock) -> EurofurenceApplicationBuilder {
        self.clock = clock
        return self
    }

    @discardableResult
    func with(_ credentialStore: CredentialStore) -> EurofurenceApplicationBuilder {
        self.credentialStore = credentialStore
        return self
    }

    @discardableResult
    func with(_ loginAPI: LoginAPI) -> EurofurenceApplicationBuilder {
        self.loginAPI = loginAPI
        return self
    }

    @discardableResult
    func with(_ privateMessagesAPI: PrivateMessagesAPI) -> EurofurenceApplicationBuilder {
        self.privateMessagesAPI = privateMessagesAPI
        return self
    }

    @discardableResult
    func with(_ syncAPI: SyncAPI) -> EurofurenceApplicationBuilder {
        self.syncAPI = syncAPI
        return self
    }

    @discardableResult
    func with(_ dateDistanceCalculator: DateDistanceCalculator) -> EurofurenceApplicationBuilder {
        self.dateDistanceCalculator = dateDistanceCalculator
        return self
    }

    @discardableResult
    func with(_ conventionStartDateRepository: ConventionStartDateRepository) -> EurofurenceApplicationBuilder {
        self.conventionStartDateRepository = conventionStartDateRepository
        return self
    }

    @discardableResult
    func with(_ significantTimeChangeEventSource: SignificantTimeChangeEventSource) -> EurofurenceApplicationBuilder {
        self.significantTimeChangeEventSource = significantTimeChangeEventSource
        return self
    }

    @discardableResult
    func with(timeIntervalForUpcomingEventsSinceNow: TimeInterval) -> EurofurenceApplicationBuilder {
        self.timeIntervalForUpcomingEventsSinceNow = timeIntervalForUpcomingEventsSinceNow
        return self
    }

    @discardableResult
    func with(_ imageAPI: ImageAPI) -> EurofurenceApplicationBuilder {
        self.imageAPI = imageAPI
        return self
    }

    @discardableResult
    func with(_ imageRepository: ImageRepository) -> EurofurenceApplicationBuilder {
        self.imageRepository = imageRepository
        return self
    }

    func build() -> EurofurenceApplicationProtocol {
        return EurofurenceApplication(userPreferences: userPreferences,
                                      dataStore: dataStore,
                                      remoteNotificationsTokenRegistration: remoteNotificationsTokenRegistration,
                                      pushPermissionsRequester: pushPermissionsRequester,
                                      pushPermissionsStateProviding: pushPermissionsStateProviding,
                                      clock: clock,
                                      credentialStore: credentialStore,
                                      loginAPI: loginAPI,
                                      privateMessagesAPI: privateMessagesAPI,
                                      syncAPI: syncAPI,
                                      imageAPI: imageAPI,
                                      dateDistanceCalculator: dateDistanceCalculator,
                                      conventionStartDateRepository: conventionStartDateRepository,
                                      significantTimeChangeEventSource: significantTimeChangeEventSource,
                                      timeIntervalForUpcomingEventsSinceNow: timeIntervalForUpcomingEventsSinceNow,
                                      imageRepository: imageRepository)
    }

}

{'fraction_non_alphanumeric': 0.04677154832047622, 'fraction_numerical': 0.0026726599040272124, 'mean_word_length': 2.5014887282007656, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 54, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6077372', 'n_tokens_mistral': 3723, 'n_tokens_neox': 3506, 'n_words': 750}