Skip to content

Refactor nested ifs into a switch statement #4132

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 13, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 9 additions & 15 deletions Sources/Workspace/Workspace.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3350,22 +3350,16 @@ extension Workspace {
}

case .version(let version):
if let currentDependency = currentDependency {
// FIXME: This should probably be refactored into a switch statement to avoid missing new cases.
if case .sourceControlCheckout(let checkoutState) = currentDependency.state, case .version(version, _) = checkoutState {
packageStateChanges[packageRef.identity] = (packageRef, .unchanged)
} else if case .registryDownload(version) = currentDependency.state {
packageStateChanges[packageRef.identity] = (packageRef, .unchanged)
} else if case .custom(version, _) = currentDependency.state {
packageStateChanges[packageRef.identity] = (packageRef, .unchanged)
} else {
let newState = PackageStateChange.State(requirement: .version(version), products: products)
packageStateChanges[packageRef.identity] = (packageRef, .updated(newState))
}
} else {
let newState = PackageStateChange.State(requirement: .version(version), products: products)
packageStateChanges[packageRef.identity] = (packageRef, .added(newState))
let stateChange: PackageStateChange
switch currentDependency?.state {
case .sourceControlCheckout(.version(version, _)), .registryDownload(version), .custom(version, _):
stateChange = .unchanged
case .edited, .fileSystem, .sourceControlCheckout, .registryDownload, .custom:
stateChange = .updated(.init(requirement: .version(version), products: products))
case nil:
stateChange = .added(.init(requirement: .version(version), products: products))
}
packageStateChanges[packageRef.identity] = (packageRef, stateChange)
}
}
// Set the state of any old package that might have been removed.
Expand Down