Skip to content

Instantly share code, notes, and snippets.

@helium-service
Created May 13, 2024 17:11
Show Gist options
  • Save helium-service/4aa83eafa2cd82ac9c67986ce08cf69b to your computer and use it in GitHub Desktop.
Save helium-service/4aa83eafa2cd82ac9c67986ce08cf69b to your computer and use it in GitHub Desktop.
Detekt Report for PR #1769 Timestamp 1715619807

detekt

Metrics

  • 61 number of properties

  • 27 number of functions

  • 16 number of classes

  • 2 number of packages

  • 3 number of kt files

Complexity Report

  • 1,197 lines of code (loc)

  • 858 source lines of code (sloc)

  • 670 logical lines of code (lloc)

  • 235 comment lines of code (cloc)

  • 121 cyclomatic complexity (mcc)

  • 79 cognitive complexity

  • 32 number of total code smells

  • 27% comment source ratio

  • 180 mcc per 1,000 lloc

  • 47 code smells per 1,000 lloc

Findings (32)

complexity, CyclomaticComplexMethod (1)

Prefer splitting up complex methods into smaller, easier to test methods.

Documentation

  • /Users/cbx/actions-runner/_work/helium-android/helium-android/Helium/src/main/java/com/chartboost/heliumsdk/controllers/PartnerController.kt:111:9
The function setUpAdapters appears to be too complex based on Cyclomatic Complexity (complexity: 19). Defined complexity threshold for methods is set to '15'
108      * @param skippedPartnerIds A Set of partners whose initialization should be skipped as per the publisher's request.
109      * @param onPartnerInitializationComplete A callback to be invoked when the initialization is deemed complete.
110      */
111     fun setUpAdapters(
!!!         ^ error
112         context: Context,
113         partnerConfigurationMap: Map<String, PartnerConfiguration>,
114         adapterClasses: Set<String>,

complexity, LargeClass (1)

One class should have one responsibility. Large classes tend to handle many things at once. Split up large classes into smaller classes that are easier to understand.

Documentation

  • /Users/cbx/actions-runner/_work/helium-android/helium-android/Helium/src/main/java/com/chartboost/heliumsdk/controllers/PartnerController.kt:52:7
Class PartnerController is too large. Consider splitting it into smaller pieces.
49 /**
50  * @suppress
51  */
52 class PartnerController {
!!       ^ error
53     companion object {
54         /**
55          * Store adapter info (versions, names, et al.) keyed by the adapter partner IDs.

complexity, LongMethod (4)

One method should have one responsibility. Long methods tend to handle many things at once. Prefer smaller methods to make them easier to understand.

Documentation

  • /Users/cbx/actions-runner/_work/helium-android/helium-android/Helium/src/main/java/com/chartboost/heliumsdk/controllers/PartnerController.kt:111:9
The function setUpAdapters is too long (93). The maximum length is 60.
108      * @param skippedPartnerIds A Set of partners whose initialization should be skipped as per the publisher's request.
109      * @param onPartnerInitializationComplete A callback to be invoked when the initialization is deemed complete.
110      */
111     fun setUpAdapters(
!!!         ^ error
112         context: Context,
113         partnerConfigurationMap: Map<String, PartnerConfiguration>,
114         adapterClasses: Set<String>,
  • /Users/cbx/actions-runner/_work/helium-android/helium-android/Helium/src/main/java/com/chartboost/heliumsdk/controllers/PartnerController.kt:332:17
The function routeGetBidderInformation is too long (68). The maximum length is 60.
329      * @param context The context to use for the call.
330      * @param request The [PreBidRequest] instance containing data necessary for this operation.
331      */
332     suspend fun routeGetBidderInformation(
!!!                 ^ error
333         context: Context,
334         request: PreBidRequest,
335     ): Map<String, Map<String, String>> {
  • /Users/cbx/actions-runner/_work/helium-android/helium-android/Helium/src/main/java/com/chartboost/heliumsdk/controllers/PartnerController.kt:422:26
The function routeLoad is too long (129). The maximum length is 60.
419      * @param isMediation True if this is a mediation request, false if it's a bidding one.
420      * @param request The [PartnerAdLoadRequest] instance containing data necessary for this operation.
421      */
422     internal suspend fun routeLoad(
!!!                          ^ error
423         context: Context,
424         auctionId: String,
425         lineItemId: String?,
  • /Users/cbx/actions-runner/_work/helium-android/helium-android/Helium/src/main/java/com/chartboost/heliumsdk/controllers/PartnerController.kt:578:17
The function routeShow is too long (94). The maximum length is 60.
575      * @param partnerAd The [PartnerAd] to attempt to show.
576      * @param auctionIdentifier The current auction ID.
577      */
578     suspend fun routeShow(
!!!                 ^ error
579         context: Context,
580         partnerAd: PartnerAd?,
581         auctionIdentifier: String,

complexity, LongParameterList (1)

The more parameters a function has the more complex it is. Long parameter lists are often used to control complex algorithms and violate the Single Responsibility Principle. Prefer functions with short parameter lists.

Documentation

  • /Users/cbx/actions-runner/_work/helium-android/helium-android/Helium/src/main/java/com/chartboost/heliumsdk/controllers/PartnerController.kt:422:35
The function routeLoad(context: Context, auctionId: String, lineItemId: String?, isMediation: Boolean, request: PartnerAdLoadRequest, loadMetricsSet: MutableSet<Metrics>, placementType: String?) has too many parameters. The current threshold is set to 6.
419      * @param isMediation True if this is a mediation request, false if it's a bidding one.
420      * @param request The [PartnerAdLoadRequest] instance containing data necessary for this operation.
421      */
422     internal suspend fun routeLoad(
!!!                                   ^ error
423         context: Context,
424         auctionId: String,
425         lineItemId: String?,

complexity, NestedBlockDepth (1)

Excessive nesting leads to hidden complexity. Prefer extracting code to make it easier to understand.

Documentation

  • /Users/cbx/actions-runner/_work/helium-android/helium-android/Helium/src/main/java/com/chartboost/heliumsdk/controllers/PartnerController.kt:272:9
Function setCcpaConsent is nested too deeply.
269      * @param privacyString The CCPA privacy string.
270      * @param partnerConsents Per-partner consents.
271      */
272     fun setCcpaConsent(
!!!         ^ error
273         context: Context,
274         hasGrantedCcpaConsent: Boolean?,
275         privacyString: String,

complexity, TooManyFunctions (1)

Too many functions inside a/an file/class/object/interface always indicate a violation of the single responsibility principle. Maybe the file/class/object/interface wants to manage too many things at once. Extract functionality which clearly belongs together.

Documentation

  • /Users/cbx/actions-runner/_work/helium-android/helium-android/Helium/src/main/java/com/chartboost/heliumsdk/controllers/PartnerController.kt:52:7
Class 'PartnerController' with '17' functions detected. Defined threshold inside classes is set to '11'
49 /**
50  * @suppress
51  */
52 class PartnerController {
!!       ^ error
53     companion object {
54         /**
55          * Store adapter info (versions, names, et al.) keyed by the adapter partner IDs.

exceptions, SwallowedException (1)

The caught exception is swallowed. The original exception could be lost.

Documentation

  • /Users/cbx/actions-runner/_work/helium-android/helium-android/Helium/src/main/java/com/chartboost/heliumsdk/controllers/PrivacyController.kt:174:26
The caught exception is swallowed. The original exception could be lost.
171                     }
172                     partnerConsents.mergePartnerConsentsFromDisk(consentMap)
173                     savePartnerConsentsToDisk()
174                 } catch (e: JSONException) {
!!!                          ^ error
175                     LogController.d("Unable to recreate partner consents map.")
176                 }
177             }

exceptions, TooGenericExceptionCaught (6)

The caught exception is too generic. Prefer catching specific exceptions to the case that is currently handled.

Documentation

  • /Users/cbx/actions-runner/_work/helium-android/helium-android/Helium/src/main/java/com/chartboost/heliumsdk/controllers/PartnerController.kt:388:54
The caught exception is too generic. Prefer catching specific exceptions to the case that is currently handled.
385 
386                                                         result
387                                                     }
388                                             } catch (e: Exception) {
!!!                                                      ^ error
389                                                 metrics.end = System.currentTimeMillis()
390                                                 metrics.isSuccess = false
391                                                 metrics.chartboostMediationError =
  • /Users/cbx/actions-runner/_work/helium-android/helium-android/Helium/src/main/java/com/chartboost/heliumsdk/controllers/PartnerController.kt:513:46
The caught exception is too generic. Prefer catching specific exceptions to the case that is currently handled.
510                                             handleLoadResult(it, metrics)
511                                             result = it
512                                         }
513                                     } catch (e: Exception) {
!!!                                              ^ error
514                                         metrics.end = System.currentTimeMillis()
515                                         metrics.isSuccess = false
516                                         metrics.chartboostMediationError =
  • /Users/cbx/actions-runner/_work/helium-android/helium-android/Helium/src/main/java/com/chartboost/heliumsdk/controllers/PartnerController.kt:661:38
The caught exception is too generic. Prefer catching specific exceptions to the case that is currently handled.
658                         measureTimeMillis {
659                             try {
660                                 handleShowResult(adapter.show(context, partnerAd), metrics)
661                             } catch (e: Exception) {
!!!                                      ^ error
662                                 metrics.end = System.currentTimeMillis()
663                                 metrics.isSuccess = false
664                                 metrics.chartboostMediationError =
  • /Users/cbx/actions-runner/_work/helium-android/helium-android/Helium/src/main/java/com/chartboost/heliumsdk/controllers/PartnerController.kt:722:22
The caught exception is too generic. Prefer catching specific exceptions to the case that is currently handled.
719 
720                 adapters[adapter.partnerId] = adapter
721                 initStatuses[adapter.partnerId] = PartnerInitializationStatus.IDLE
722             } catch (exception: Exception) {
!!!                      ^ error
723                 LogController.e(
724                     "Failed to create adapter $name. Error: ${exception.message}." +
725                         "The associated network will not be initialized.",
  • /Users/cbx/actions-runner/_work/helium-android/helium-android/Helium/src/main/java/com/chartboost/heliumsdk/controllers/PartnerController.kt:754:18
The caught exception is too generic. Prefer catching specific exceptions to the case that is currently handled.
751 
752                 handleSetupResult(it, adapter, metrics)
753             }
754         } catch (exception: Exception) {
!!!                  ^ error
755             metrics.end = System.currentTimeMillis()
756             metrics.duration = metrics.end?.minus(metrics.start ?: 0) ?: 0
757             metrics.isSuccess = false
  • /Users/cbx/actions-runner/_work/helium-android/helium-android/Helium/src/main/java/com/chartboost/heliumsdk/controllers/PartnerController.kt:821:18
The caught exception is too generic. Prefer catching specific exceptions to the case that is currently handled.
818                     partnerId = adapter.partnerId,
819                     partnerDisplayName = adapter.partnerDisplayName,
820                 )
821         } catch (exception: Exception) {
!!!                  ^ error
822             LogController.e(
823                 "Failed to make AdapterInfo for " + "${adapter.partnerDisplayName}. Its version data will not be available." + " Error: ${
824                     (exception as? ChartboostMediationAdException)?.chartboostMediationError ?: ChartboostMediationError.CM_INITIALIZATION_FAILURE_EXCEPTION

style, ForbiddenComment (1)

Flags a forbidden comment.

Documentation

  • /Users/cbx/actions-runner/_work/helium-android/helium-android/Helium/src/main/java/com/chartboost/heliumsdk/controllers/PrivacyController.kt:103:6
Forbidden TODO todo marker in comment, please do the changes.
100         }
101 
102     /**
103      * This represents a user consent when GDPR applies (int 0 or 1).
!!!      ^ error
104      * This is only sent if GDPR is specifically set to 1.
105      * If GDPR is not set, or it is set to 0, do not send the node at all.
106      * TODO: What if user consent is not set?

style, MagicNumber (9)

Report magic numbers. Magic number is a numeric literal that is not defined as a constant and hence it's unclear what the purpose of this number is. It's better to declare such numbers as constants and give them a proper name. By default, -1, 0, 1, and 2 are not considered to be magic numbers.

Documentation

  • /Users/cbx/actions-runner/_work/helium-android/helium-android/Helium/src/main/java/com/chartboost/heliumsdk/controllers/PartnerController.kt:67:16
This expression contains a magic number. Consider defining it to a well named constant.
64         IDLE(0), // Initialization not started (the default state).
65         INITIALIZING(1), // Initialization is in progress.
66         INITIALIZED(2), // Initialization has been successfully completed.
67         FAILED(3), // Initialization has failed.
!!                ^ error
68         SKIPPED(4), // Initialization deliberately skipped by the publisher.
69     }
70 
  • /Users/cbx/actions-runner/_work/helium-android/helium-android/Helium/src/main/java/com/chartboost/heliumsdk/controllers/PartnerController.kt:68:17
This expression contains a magic number. Consider defining it to a well named constant.
65         INITIALIZING(1), // Initialization is in progress.
66         INITIALIZED(2), // Initialization has been successfully completed.
67         FAILED(3), // Initialization has failed.
68         SKIPPED(4), // Initialization deliberately skipped by the publisher.
!!                 ^ error
69     }
70 
71     /**
  • /Users/cbx/actions-runner/_work/helium-android/helium-android/Helium/src/main/java/com/chartboost/heliumsdk/controllers/PartnerController.kt:100:62
This expression contains a magic number. Consider defining it to a well named constant.
97       * Compute the token fetching timeout in milliseconds.
98       */
99      private val prebidFetchTimeoutMs
100         get() = AppConfigStorage.prebidFetchTimeoutSeconds * 1000L
!!!                                                              ^ error
101 
102     /**
103      * Instantiate adapters for all supplied class names, and initialize them on the main thread.
  • /Users/cbx/actions-runner/_work/helium-android/helium-android/Helium/src/main/java/com/chartboost/heliumsdk/controllers/PartnerController.kt:154:79
This expression contains a magic number. Consider defining it to a well named constant.
151             // Report init completion to Chartboost Mediation once the time is up anyway, but still let the
152             // partners in question finish initialization (they are not cancelled).
153             val timer =
154                 Timer().schedule(AppConfigStorage.partnerInitTimeoutSeconds * 1000L) {
!!!                                                                               ^ error
155                     if (!initCompletionReported) {
156                         cancel()
157 
  • /Users/cbx/actions-runner/_work/helium-android/helium-android/Helium/src/main/java/com/chartboost/heliumsdk/controllers/PartnerController.kt:186:82
This expression contains a magic number. Consider defining it to a well named constant.
183                 adapters.remove(partnerId)
184             }
185 
186             Timer().schedule(AppConfigStorage.initializationMetricsPostTimeout * 1000L) {
!!!                                                                                  ^ error
187                 MetricsManager.postMetricsData(
188                     metricsDataSet,
189                     eventResult =
  • /Users/cbx/actions-runner/_work/helium-android/helium-android/Helium/src/main/java/com/chartboost/heliumsdk/controllers/PartnerController.kt:655:77
This expression contains a magic number. Consider defining it to a well named constant.
652                 adapters[partnerAd.request.partnerId]?.let { adapter ->
653                     metrics.auctionId = auctionIdentifier
654 
655                     withTimeoutOrNull(AppConfigStorage.showTimeoutSeconds * 1000L) {
!!!                                                                             ^ error
656                         metrics.start = System.currentTimeMillis()
657 
658                         measureTimeMillis {
  • /Users/cbx/actions-runner/_work/helium-android/helium-android/Helium/src/main/java/com/chartboost/heliumsdk/controllers/PartnerController.kt:862:102
This expression contains a magic number. Consider defining it to a well named constant.
859      */
860     private fun getLoadTimeoutMs(format: AdFormat): Long {
861         return when (format) {
862             AdFormat.BANNER, AdFormat.ADAPTIVE_BANNER -> AppConfigStorage.bannerLoadTimeoutSeconds * 1000L
!!!                                                                                                      ^ error
863 
864             AdFormat.INTERSTITIAL, AdFormat.REWARDED, AdFormat.REWARDED_INTERSTITIAL -> AppConfigStorage.fullscreenLoadTimeoutSeconds * 1000L
865 
  • /Users/cbx/actions-runner/_work/helium-android/helium-android/Helium/src/main/java/com/chartboost/heliumsdk/controllers/PartnerController.kt:864:137
This expression contains a magic number. Consider defining it to a well named constant.
861         return when (format) {
862             AdFormat.BANNER, AdFormat.ADAPTIVE_BANNER -> AppConfigStorage.bannerLoadTimeoutSeconds * 1000L
863 
864             AdFormat.INTERSTITIAL, AdFormat.REWARDED, AdFormat.REWARDED_INTERSTITIAL -> AppConfigStorage.fullscreenLoadTimeoutSeconds * 1000L
!!!                                                                                                                                         ^ error
865 
866             else -> {
867                 LogController.e("Unknown ad format: $format. Using default timeout.")
  • /Users/cbx/actions-runner/_work/helium-android/helium-android/Helium/src/main/java/com/chartboost/heliumsdk/controllers/PartnerController.kt:868:65
This expression contains a magic number. Consider defining it to a well named constant.
865 
866             else -> {
867                 LogController.e("Unknown ad format: $format. Using default timeout.")
868                 AppConfigStorage.fullscreenLoadTimeoutSeconds * 1000L
!!!                                                                 ^ error
869             }
870         }
871     }

style, MaxLineLength (6)

Line detected, which is longer than the defined maximum line length in the code style.

Documentation

  • /Users/cbx/actions-runner/_work/helium-android/helium-android/Helium/src/main/java/com/chartboost/heliumsdk/controllers/PartnerController.kt:469:1
Line detected, which is longer than the defined maximum line length in the code style.
466                         partnerPlacement = request.partnerPlacement,
467                     )
468                     result =
469                         Result.failure(ChartboostMediationAdException(ChartboostMediationError.CM_LOAD_FAILURE_EXCEPTION))
!!! ^ error
470                 },
471             ) {
472                 withContext(IO) {
  • /Users/cbx/actions-runner/_work/helium-android/helium-android/Helium/src/main/java/com/chartboost/heliumsdk/controllers/PartnerController.kt:477:1
Line detected, which is longer than the defined maximum line length in the code style.
474                         adapters[request.partnerId]?.let { adapter ->
475                             val metrics = Metrics(adapter.partnerId, LOAD)
476 
477                             // Since it's possible for a Chartboost Mediation placement to consist of multiple line items
!!! ^ error
478                             // at load time and we are tracking metrics data per line item, we need to batch data for
479                             // the same placement in the same dataset.
480                             loadMetricsSet.add(metrics)
  • /Users/cbx/actions-runner/_work/helium-android/helium-android/Helium/src/main/java/com/chartboost/heliumsdk/controllers/PartnerController.kt:538:1
Line detected, which is longer than the defined maximum line length in the code style.
535                                 event = LOAD,
536                                 auctionIdentifier = auctionId,
537                                 chartboostMediationError = ChartboostMediationError.CM_LOAD_FAILURE_ADAPTER_NOT_FOUND,
538                                 chartboostMediationErrorMessage = ChartboostMediationError.CM_LOAD_FAILURE_ADAPTER_NOT_FOUND.message,
!!! ^ error
539                                 loadId = request.identifier,
540                                 placementType = placementType,
541                                 size = request.size?.takeIf { (placementType == "adaptive_banner") },
  • /Users/cbx/actions-runner/_work/helium-android/helium-android/Helium/src/main/java/com/chartboost/heliumsdk/controllers/PartnerController.kt:545:1
Line detected, which is longer than the defined maximum line length in the code style.
542                             )
543 
544                             result =
545                                 Result.failure(ChartboostMediationAdException(ChartboostMediationError.CM_LOAD_FAILURE_ADAPTER_NOT_FOUND))
!!! ^ error
546                         }
547                     } ?: run {
548                         MetricsManager.postMetricsDataForFailedEvent(
  • /Users/cbx/actions-runner/_work/helium-android/helium-android/Helium/src/main/java/com/chartboost/heliumsdk/controllers/PartnerController.kt:563:1
Line detected, which is longer than the defined maximum line length in the code style.
560                         )
561 
562                         result =
563                             Result.failure(ChartboostMediationAdException(ChartboostMediationError.CM_LOAD_FAILURE_TIMEOUT))
!!! ^ error
564                     }
565                 }
566             }
  • /Users/cbx/actions-runner/_work/helium-android/helium-android/Helium/src/main/java/com/chartboost/heliumsdk/controllers/PartnerController.kt:864:1
Line detected, which is longer than the defined maximum line length in the code style.
861         return when (format) {
862             AdFormat.BANNER, AdFormat.ADAPTIVE_BANNER -> AppConfigStorage.bannerLoadTimeoutSeconds * 1000L
863 
864             AdFormat.INTERSTITIAL, AdFormat.REWARDED, AdFormat.REWARDED_INTERSTITIAL -> AppConfigStorage.fullscreenLoadTimeoutSeconds * 1000L
!!! ^ error
865 
866             else -> {
867                 LogController.e("Unknown ad format: $format. Using default timeout.")

generated with detekt version 1.23.5 on 2024-05-13 17:11:34 UTC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment