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:
2026-05-26 20:46:33 -04:00
parent ae45e8f32e
commit b1bcfe7fa3
@@ -39,13 +39,16 @@ class PasswordViewModel @Inject constructor(
fun change() {
val s = internal.value
if (s.isChanging) return
if (s.current.isEmpty() || s.next.isEmpty()) {
internal.update { it.copy(message = "All fields required.") }
return
val validationError: String? = when {
s.isChanging -> "" // sentinel: silent no-op
s.current.isEmpty() || s.next.isEmpty() -> "All fields required."
s.next != s.confirm -> "New passwords do not match."
else -> null
}
if (s.next != s.confirm) {
internal.update { it.copy(message = "New passwords do not match.") }
if (validationError != null) {
if (validationError.isNotEmpty()) {
internal.update { it.copy(message = validationError) }
}
return
}
viewModelScope.launch {