Skip to content

Commit bda262f

Browse files
committed
refactor: drop @Suppress("ReturnCount") via 2-return form
Detekt's ReturnCount rule defaults to a max of 2; the previous body had 3 (early null/type guard, divergence guard, final result) which forced the suppression. Collapse the divergence branch into a trailing `return if (divergent) ... else null` expression so the function uses exactly two `return` keywords: 1. early `return null` for the cache miss / non-push guard 2. final `return if (divergent) { ... } else { null }` No behavior change. Addresses review feedback on #2636. Refs: SDK-4474
1 parent 147baad commit bda262f

1 file changed

Lines changed: 21 additions & 21 deletions

File tree

OneSignalSDK/onesignal/core/src/main/java/com/onesignal/user/internal/operations/impl/executors/RefreshUserOperationExecutor.kt

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,6 @@ internal class RefreshUserOperationExecutor(
207207
* Caller has already verified that [serverSubscription.id] matches the cached
208208
* `pushSubscriptionId`, so this method only inspects the local model + server flags.
209209
*/
210-
@Suppress("ReturnCount")
211210
private fun buildPushSelfHealOperationForStuckSubscription(
212211
op: RefreshUserOperation,
213212
serverSubscription: SubscriptionObject,
@@ -220,27 +219,28 @@ internal class RefreshUserOperationExecutor(
220219

221220
val (localEnabled, localStatus) = SubscriptionModelStoreListener.getSubscriptionEnabledAndStatus(cachedPushSubscriptionModel)
222221
val serverEnabled = (serverSubscription.enabled == true) && ((serverSubscription.notificationTypes ?: 0) > 0)
223-
if (!localEnabled || serverEnabled) {
224-
return null
222+
val divergent = localEnabled && !serverEnabled
223+
224+
return if (divergent) {
225+
Logging.info(
226+
"RefreshUserOperationExecutor: push subscription $pushSubscriptionId diverged from server " +
227+
"(server enabled=${serverSubscription.enabled} notificationTypes=${serverSubscription.notificationTypes}; " +
228+
"local opted-in and SUBSCRIBED). Enqueuing follow-up update-subscription op to re-assert local " +
229+
"truth via PATCH /subscriptions/{id}. See SDK-4388 / SDK-4474.",
230+
)
231+
UpdateSubscriptionOperation(
232+
op.appId,
233+
op.onesignalId,
234+
_identityModelStore.model.externalId,
235+
pushSubscriptionId,
236+
cachedPushSubscriptionModel.type,
237+
localEnabled,
238+
cachedPushSubscriptionModel.address,
239+
localStatus,
240+
)
241+
} else {
242+
null
225243
}
226-
227-
Logging.info(
228-
"RefreshUserOperationExecutor: push subscription $pushSubscriptionId diverged from server " +
229-
"(server enabled=${serverSubscription.enabled} notificationTypes=${serverSubscription.notificationTypes}; " +
230-
"local opted-in and SUBSCRIBED). Enqueuing follow-up update-subscription op to re-assert local " +
231-
"truth via PATCH /subscriptions/{id}. See SDK-4388 / SDK-4474.",
232-
)
233-
234-
return UpdateSubscriptionOperation(
235-
op.appId,
236-
op.onesignalId,
237-
_identityModelStore.model.externalId,
238-
pushSubscriptionId,
239-
cachedPushSubscriptionModel.type,
240-
localEnabled,
241-
cachedPushSubscriptionModel.address,
242-
localStatus,
243-
)
244244
}
245245

246246
companion object {

0 commit comments

Comments
 (0)