Skip to content

Instantly share code, notes, and snippets.

@helium-service
Created February 6, 2025 15:03
Show Gist options
  • Save helium-service/8600e37fcffe1c28b4a80f90cd7429e9 to your computer and use it in GitHub Desktop.
Save helium-service/8600e37fcffe1c28b4a80f90cd7429e9 to your computer and use it in GitHub Desktop.
Detekt Report for PR #2026 Timestamp 1738854141

detekt

Metrics

  • 124 number of properties

  • 93 number of functions

  • 38 number of classes

  • 3 number of packages

  • 20 number of kt files

Complexity Report

  • 1,178 lines of code (loc)

  • 922 source lines of code (sloc)

  • 739 logical lines of code (lloc)

  • 56 comment lines of code (cloc)

  • 136 cyclomatic complexity (mcc)

  • 30 cognitive complexity

  • 14 number of total code smells

  • 6% comment source ratio

  • 184 mcc per 1,000 lloc

  • 18 code smells per 1,000 lloc

Findings (14)

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/ChartboostMonetization/src/main/java/com/chartboost/sdk/internal/mraid/MonetizationMraidController.kt:12:7
Class 'MonetizationMraidController' with '15' functions detected. Defined threshold inside classes is set to '11'
9  import com.chartboost.sdk.internal.renderables.StopReason
10 import java.net.URL
11 
12 class MonetizationMraidController(
!!       ^ error
13     private var context: Context,
14     private val webView: WebView,
15     private val placementType: Mraid.PlacementType,

empty-blocks, EmptyFunctionBlock (2)

Empty block of code detected. As they serve no purpose they should be removed.

Documentation

  • /Users/cbx/actions-runner/_work/helium-android/helium-android/ChartboostMonetization/src/main/java/com/chartboost/sdk/internal/renderables/WebRenderable.kt:149:62
This empty block of code can be removed.
146         }
147     }
148 
149     override fun onWebViewStopped(reason: WebViewStopReason) {
!!!                                                              ^ error
150     }
151 
152     override fun onOrientationRequest(request: MraidOrientationRequest) {
  • /Users/cbx/actions-runner/_work/helium-android/helium-android/ChartboostMonetization/src/main/java/com/chartboost/sdk/internal/renderables/WebRenderable.kt:152:73
This empty block of code can be removed.
149     override fun onWebViewStopped(reason: WebViewStopReason) {
150     }
151 
152     override fun onOrientationRequest(request: MraidOrientationRequest) {
!!!                                                                         ^ error
153     }
154 }
155 

exceptions, SwallowedException (1)

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

Documentation

  • /Users/cbx/actions-runner/_work/helium-android/helium-android/ChartboostMonetization/src/main/java/com/chartboost/sdk/internal/mraid/MonetizationMraidController.kt:126:18
The caught exception is swallowed. The original exception could be lost.
123                 MraidJSToNativeCommand.SET_ORIENTATION_PROPERTIES -> handleSetOrientationProperties(url)
124                 MraidJSToNativeCommand.UNLOAD -> handleUnload()
125             }
126         } catch (e: IllegalArgumentException) {
!!!                  ^ error
127             false
128         }
129     }

naming, InvalidPackageDeclaration (1)

Kotlin source files should be stored in the directory corresponding to its package statement.

Documentation

  • /Users/cbx/actions-runner/_work/helium-android/helium-android/ChartboostMonetization/src/main/java/com/chartboost/sdk/internal/Utils/Dips.kt:1:1
The package declaration does not match the actual file location.
1 package com.chartboost.sdk.internal.utils
! ^ error
2 
3 import android.content.Context
4 import kotlin.math.roundToInt

style, MaxLineLength (5)

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/ChartboostMonetization/src/main/java/com/chartboost/sdk/internal/mraid/MRAIDNativeToJSCommand.kt:14:1
Line detected, which is longer than the defined maximum line length in the code style.
11         fun setCurrentPosition(screenMetrics: MraidScreenMetrics): MRAIDNativeToJSCommand {
12             val current = screenMetrics.currentRectDips
13             return MRAIDNativeToJSCommand(
14                 "window.mraidbridge.setCurrentPosition(${current.x}, ${current.y}, ${current.width}, ${current.height});",
!! ^ error
15             )
16         }
17 
  • /Users/cbx/actions-runner/_work/helium-android/helium-android/ChartboostMonetization/src/main/java/com/chartboost/sdk/internal/mraid/MRAIDNativeToJSCommand.kt:21:1
Line detected, which is longer than the defined maximum line length in the code style.
18         fun setDefaultPosition(screenMetrics: MraidScreenMetrics): MRAIDNativeToJSCommand {
19             val default = screenMetrics.defaultRectDips
20             return MRAIDNativeToJSCommand(
21                 "window.mraidbridge.setDefaultPosition(${default.x}, ${default.y}, ${default.width}, ${default.height});",
!! ^ error
22             )
23         }
24 
  • /Users/cbx/actions-runner/_work/helium-android/helium-android/ChartboostMonetization/src/main/java/com/chartboost/sdk/internal/mraid/MRAIDNativeToJSCommand.kt:41:1
Line detected, which is longer than the defined maximum line length in the code style.
38 
39         fun fireSizeChangeEvent(screenMetrics: MraidScreenMetrics): MRAIDNativeToJSCommand {
40             val current = screenMetrics.maxRectDips
41             return MRAIDNativeToJSCommand("window.mraidbridge.notifySizeChangeEvent(${current.width}, ${current.height});")
!! ^ error
42         }
43 
44         fun fireStateChangeEvent(state: Mraid.State): MRAIDNativeToJSCommand {
  • /Users/cbx/actions-runner/_work/helium-android/helium-android/ChartboostMonetization/src/test/java/com/chartboost/sdk/internal/mraid/MraidNativeToJSCommandTests.kt:32:1
Line detected, which is longer than the defined maximum line length in the code style.
29     @Test
30     fun `verify MRAID setPlacement javascript string`() {
31         // INTERSTITIAL
32         val interstitial: MRAIDNativeToJSCommand = MRAIDNativeToJSCommand.setPlacementType(Mraid.PlacementType.INTERSTITIAL)
!! ^ error
33         assertEquals("window.mraidbridge.setPlacementType('interstitial');", interstitial.javascript)
34 
35         // INLINE
  • /Users/cbx/actions-runner/_work/helium-android/helium-android/ChartboostMonetization/src/test/java/com/chartboost/sdk/internal/renderables/WebRenderableTest.kt:44:1
Line detected, which is longer than the defined maximum line length in the code style.
41 
42         whenever(webView.settings).thenReturn(webSettings)
43         whenever(webViewFactory.createWebView(context)).thenReturn(webView)
44         whenever(webViewFactory.createMRAIDController(context, webView, Mraid.PlacementType.INTERSTITIAL)).thenReturn(mraidController)
!! ^ error
45     }
46 
47     @Test

style, ReturnCount (2)

Restrict the number of return statements in methods.

Documentation

  • /Users/cbx/actions-runner/_work/helium-android/helium-android/ChartboostMonetization/src/main/java/com/chartboost/sdk/internal/mraid/MonetizationMraidController.kt:131:17
Function handleOpen has 3 return statements which exceeds the limit of 2.
128         }
129     }
130 
131     private fun handleOpen(url: Uri): Boolean {
!!!                 ^ error
132         val listener = this.listener ?: return false
133         val parameters = parametersFrom(url)
134         val urlString = parameters["url"] ?: return false
  • /Users/cbx/actions-runner/_work/helium-android/helium-android/ChartboostMonetization/src/main/java/com/chartboost/sdk/internal/mraid/MonetizationMraidController.kt:140:17
Function handleSetOrientationProperties has 3 return statements which exceeds the limit of 2.
137         return true
138     }
139 
140     private fun handleSetOrientationProperties(url: Uri): Boolean {
!!!                 ^ error
141         val listener = this.listener ?: return false
142         val parameters = parametersFrom(url)
143         val forceOrientationValue = parameters["forceOrientation"] ?: return false

style, UseRequire (1)

Use require() instead of throwing an IllegalArgumentException.

Documentation

  • /Users/cbx/actions-runner/_work/helium-android/helium-android/ChartboostMonetization/src/main/java/com/chartboost/sdk/internal/renderables/WebRenderable.kt:45:13
Use require() instead of throwing an IllegalArgumentException.
42 
43     init {
44         if (html == null && url == null) {
45             throw IllegalArgumentException("Either HTML or URL must be provided")
!!             ^ error
46         }
47     }
48 

style, WildcardImport (1)

Wildcard imports should be replaced with imports using fully qualified class names. Wildcard imports can lead to naming conflicts. A library update can introduce naming clashes with your classes which results in compilation errors.

Documentation

  • /Users/cbx/actions-runner/_work/helium-android/helium-android/ChartboostMonetization/src/test/java/com/chartboost/sdk/internal/mraid/MonetizationMraidControllerTests.kt:12:1
org.mockito.Mockito.* is a wildcard import. Replace it with fully qualified imports.
9  import org.junit.jupiter.api.BeforeEach
10 import org.junit.jupiter.api.Test
11 import org.mockito.Mockito
12 import org.mockito.Mockito.*
!! ^ error
13 import org.mockito.kotlin.whenever
14 
15 class MonetizationMraidControllerTests {

generated with detekt version 1.23.5 on 2025-02-06 15:03:26 UTC

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