fix(android): detekt ReturnCount on PasswordViewModel.change (3/2)
Combined the three early-bail checks (isChanging guard, empty-fields validation, mismatch validation) into one when-expression with a single return. Sentinel empty-string distinguishes "silent no-op because already changing" from "user-facing validation error". Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -39,13 +39,16 @@ class PasswordViewModel @Inject constructor(
|
|||||||
|
|
||||||
fun change() {
|
fun change() {
|
||||||
val s = internal.value
|
val s = internal.value
|
||||||
if (s.isChanging) return
|
val validationError: String? = when {
|
||||||
if (s.current.isEmpty() || s.next.isEmpty()) {
|
s.isChanging -> "" // sentinel: silent no-op
|
||||||
internal.update { it.copy(message = "All fields required.") }
|
s.current.isEmpty() || s.next.isEmpty() -> "All fields required."
|
||||||
return
|
s.next != s.confirm -> "New passwords do not match."
|
||||||
|
else -> null
|
||||||
}
|
}
|
||||||
if (s.next != s.confirm) {
|
if (validationError != null) {
|
||||||
internal.update { it.copy(message = "New passwords do not match.") }
|
if (validationError.isNotEmpty()) {
|
||||||
|
internal.update { it.copy(message = validationError) }
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
|
|||||||
Reference in New Issue
Block a user