From 4cd38aa62fe94c1cdf6e5a7ac8d104cda42f50be Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Tue, 2 Jun 2026 09:50:05 -0400 Subject: [PATCH] fix(android): keep BaseUrlInterceptor.intercept under detekt ReturnCount MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit aec10ce7 added a third early return (the placeholder-host bail) on top of the existing unparseable-baseUrl elvis return, tripping detekt's ReturnCount ceiling of 2 on the dev test workflow. Refactor: keep the placeholder-host early bail (it preserves the no-op cost for external URLs — no AuthStore read, no URL parse), fold the unparseable-baseUrl case into a `?:` that falls back to the original URL. Result is two returns and identical observable behavior — placeholder hosts get rewritten when baseUrl parses, fall through unchanged when it doesn't. Existing unit tests cover all three paths and continue to assert the same outputs. --- .../minstrel/api/BaseUrlInterceptor.kt | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/android/app/src/main/java/com/fabledsword/minstrel/api/BaseUrlInterceptor.kt b/android/app/src/main/java/com/fabledsword/minstrel/api/BaseUrlInterceptor.kt index 06e59bc2..8bc5fee1 100644 --- a/android/app/src/main/java/com/fabledsword/minstrel/api/BaseUrlInterceptor.kt +++ b/android/app/src/main/java/com/fabledsword/minstrel/api/BaseUrlInterceptor.kt @@ -38,14 +38,18 @@ class BaseUrlInterceptor @Inject constructor( override fun intercept(chain: Interceptor.Chain): Response { val original = chain.request() + // Early-bail keeps the no-op path for external URLs cheap + // (no AuthStore read, no URL parse). if (original.url.host != PLACEHOLDER_HOST) return chain.proceed(original) - val baseUrl = authStore.baseUrl.value.toHttpUrlOrNull() - ?: return chain.proceed(original) - val rewritten: HttpUrl = original.url.newBuilder() - .scheme(baseUrl.scheme) - .host(baseUrl.host) - .port(baseUrl.port) - .build() + // Unparseable baseUrl folds into the same proceed path — keeps + // detekt's ReturnCount happy by avoiding a second early return. + val rewritten: HttpUrl = authStore.baseUrl.value.toHttpUrlOrNull()?.let { baseUrl -> + original.url.newBuilder() + .scheme(baseUrl.scheme) + .host(baseUrl.host) + .port(baseUrl.port) + .build() + } ?: original.url return chain.proceed(original.newBuilder().url(rewritten).build()) }