shop: fix detekt findings
- Commit
4796ad5f18872baffb79a7768fe3e742f8cca192- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-17 15:16 UTC (18 days ago)
- Parents
dc02b9a
Fixes every error-severity detekt finding in shop (inventory clusters C3/C4): named constants for magic numbers, extracted functions/composables for long/complex methods, wrapped long lines, removed unused parameters, and narrowed/logged exception handling. No detekt config, baseline or suppression changes; behaviour preserved. Verified: ./check shop and :shop:testDevUnitTest green.
Diff
shop/src/main/java/com/vayunmathur/shop/Navigation.kt
diff --git a/shop/src/main/java/com/vayunmathur/shop/Navigation.kt b/shop/src/main/java/com/vayunmathur/shop/Navigation.ktindex e3eabf2d8d..135be7cd8a 100644--- a/shop/src/main/java/com/vayunmathur/shop/Navigation.kt+++ b/shop/src/main/java/com/vayunmathur/shop/Navigation.kt@@ -63,31 +63,12 @@ fun Navigation( // Merchant links resolve in the ViewModel, which calls back with the destination; // this is the direct backStack call that replaces the old pendingRoute effect. // While gated, the link is left unconsumed and applies after the gate lifts.- LaunchedEffect(linkRequest, backStack.backStack.lastOrNull()) {- val url = linkRequest?.second ?: return@LaunchedEffect- if (backStack.backStack.lastOrNull() == Route.ProfileSetup) return@LaunchedEffect- viewModel.openLink(url) { route ->- if (route is Route.ProductDetail || route == Route.Search) {- applyShopPendingRoute(backStack, route, profileComplete = true)- } else {- backStack.reset(route)- }- }- }+ ShopLinkEffect(viewModel, backStack, linkRequest) LaunchedEffect(viewModel) { viewModel.loadCart(context) viewModel.loadOrders(context) }- val notificationPermission = rememberLauncherForActivityResult(ActivityResultContracts.RequestPermission()) {}- LaunchedEffect(viewModel.notificationPermissionRequest) {- if (viewModel.notificationPermissionRequest > 0 &&- Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU &&- ContextCompat.checkSelfPermission(context, Manifest.permission.POST_NOTIFICATIONS) !=- PackageManager.PERMISSION_GRANTED- ) {- notificationPermission.launch(Manifest.permission.POST_NOTIFICATIONS)- }- }+ ShopNotificationPermissionEffect(viewModel, context) if (backStack.backStack.lastOrNull() == Route.ProfileSetup) { // Gate up: no tab bar — the required profile form is the whole graph. MainNavigation(backStack) { shopEntries(backStack, viewModel, context) }@@ -107,3 +88,38 @@ fun Navigation( MainNavigation(backStack) { shopEntries(backStack, viewModel, context) } } }++/** Merchant links resolve in the ViewModel; a gated link stays unconsumed. */+@Composable+private fun ShopLinkEffect(+ viewModel: ShopViewModel,+ backStack: com.vayunmathur.library.util.NavBackStack<Route>,+ linkRequest: Pair<Int, String>?,+) {+ LaunchedEffect(linkRequest, backStack.backStack.lastOrNull()) {+ val url = linkRequest?.second ?: return@LaunchedEffect+ if (backStack.backStack.lastOrNull() == Route.ProfileSetup) return@LaunchedEffect+ viewModel.openLink(url) { route ->+ if (route is Route.ProductDetail || route == Route.Search) {+ applyShopPendingRoute(backStack, route, profileComplete = true)+ } else {+ backStack.reset(route)+ }+ }+ }+}++/** Asks for the notification permission when the ViewModel requests it. */+@Composable+private fun ShopNotificationPermissionEffect(viewModel: ShopViewModel, context: android.content.Context) {+ val notificationPermission = rememberLauncherForActivityResult(ActivityResultContracts.RequestPermission()) {}+ LaunchedEffect(viewModel.notificationPermissionRequest) {+ if (viewModel.notificationPermissionRequest > 0 &&+ Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU &&+ ContextCompat.checkSelfPermission(context, Manifest.permission.POST_NOTIFICATIONS) !=+ PackageManager.PERMISSION_GRANTED+ ) {+ notificationPermission.launch(Manifest.permission.POST_NOTIFICATIONS)+ }+ }+}
shop/src/main/java/com/vayunmathur/shop/intents/ShopAssistantBackend.kt
diff --git a/shop/src/main/java/com/vayunmathur/shop/intents/ShopAssistantBackend.kt b/shop/src/main/java/com/vayunmathur/shop/intents/ShopAssistantBackend.ktindex 66f916f819..fe0d207801 100644--- a/shop/src/main/java/com/vayunmathur/shop/intents/ShopAssistantBackend.kt+++ b/shop/src/main/java/com/vayunmathur/shop/intents/ShopAssistantBackend.kt@@ -189,8 +189,11 @@ internal suspend fun addToCart( val current = backend.cartLines(context) val shop = input.shopDomain.trim() val variantId = input.variantId.trim()- if (shop.isEmpty() || variantId.isEmpty()) return current.toCartData(ERROR_INVALID_REQUEST)- if (input.quantity !in 1..MAX_QUANTITY) return current.toCartData(ERROR_INVALID_QUANTITY)+ if (shop.isEmpty() || variantId.isEmpty() || input.quantity !in 1..MAX_QUANTITY) {+ return current.toCartData(+ if (shop.isEmpty() || variantId.isEmpty()) ERROR_INVALID_REQUEST else ERROR_INVALID_QUANTITY,+ )+ } // Exact-variant verification before any cart write (shop/AGENTS.md): // re-fetch the product and confirm this variant exists in the live // response. As in ProductScreen, the variant id doubles as the product