<commit_before>//
//  LoginPresenter.swift
//  Eurofurence
//
//  Created by <NAME> on 15/11/2017.
//  Copyright © 2017 Eurofurence. All rights reserved.
//

import Foundation

class LoginPresenter: LoginSceneDelegate {

    private let delegate: LoginModuleDelegate
    private let scene: LoginScene
    private var registrationNumber: Int?
    private var username: String?
    private var password: String?

    init(delegate: LoginModuleDelegate, scene: LoginScene) {
        self.delegate = delegate
        self.scene = scene

        scene.delegate = self
        scene.disableLoginButton()
    }

    func loginSceneDidTapCancelButton() {
        delegate.loginModuleDidCancelLogin()
    }

    func loginSceneDidUpdateRegistrationNumber(_ registrationNumberString: String) {
        let scanner = Scanner(string: registrationNumberString)
        var container = 0
        if scanner.scanInt(&container) {
            registrationNumber = container

            if username != nil && !username!.isEmpty && password != nil && !password!.isEmpty {
                scene.enableLoginButton()
            }
        }
    }

    func loginSceneDidUpdateUsername(_ username: String) {
        self.username = username

        if !username.isEmpty && registrationNumber != nil && password != nil && !password!.isEmpty {
            scene.enableLoginButton()
        }
    }

    func loginSceneDidUpdatePassword(_ password: String) {
        self.password = password

        if !password.isEmpty && !username!.isEmpty && registrationNumber != nil {
            scene.enableLoginButton()
        }
    }

}<commit_msg>Extract visibility conditional into inner class<commit_after>//
//  LoginPresenter.swift
//  Eurofurence
//
//  Created by <NAME> on 15/11/2017.
//  Copyright © 2017 Eurofurence. All rights reserved.
//

import Foundation

struct LoginPresenter: LoginSceneDelegate {

    private let delegate: LoginModuleDelegate
    private let scene: LoginScene
    private let inputContainer = InputContainer()

    private class InputContainer {
        var registrationNumber: Int?
        var username: String?
        var password: String?

        var isValid: Bool {
            guard let username = username, let password = password else { return false }
            return registrationNumber != nil && !username.isEmpty && !password.isEmpty
        }

        func updateRegistrationNumber(with string: String) {
            var container = 0
            if Scanner(string: string).scanInt(&container) {
                registrationNumber = container
            }
        }
    }

    init(delegate: LoginModuleDelegate, scene: LoginScene) {
        self.delegate = delegate
        self.scene = scene

        scene.delegate = self
        scene.disableLoginButton()
    }

    func loginSceneDidTapCancelButton() {
        delegate.loginModuleDidCancelLogin()
    }

    func loginSceneDidUpdateRegistrationNumber(_ registrationNumberString: String) {
        inputContainer.updateRegistrationNumber(with: registrationNumberString)
        if inputContainer.isValid {
            scene.enableLoginButton()
        }
    }

    func loginSceneDidUpdateUsername(_ username: String) {
        inputContainer.username = username
        if inputContainer.isValid {
            scene.enableLoginButton()
        }
    }

    func loginSceneDidUpdatePassword(_ password: String) {
        inputContainer.password = password
        if inputContainer.isValid {
            scene.enableLoginButton()
        }
    }

}
{'fraction_non_alphanumeric': 0.08163265306122448, 'fraction_numerical': 0.007369614512471655, 'mean_word_length': 2.4598039215686276, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7058604', 'n_tokens_mistral': 895, 'n_tokens_neox': 839, 'n_words': 223}