cloudinary / cloudinary_kotlin

Cloudinary Kotlin SDK library
MIT License
11 stars 4 forks source link

Analytics.kt class warnings #108

Closed TomerPacific closed 1 month ago

TomerPacific commented 1 month ago

Building the project, I noticed the following warnings for the Analytics.kt class:

  1. In the method generateOSVersionString:
private fun generateOSVersionString(major: Any, minor: Any? = "0", patch: Any? = null): String {
    val patchStr = if (patch != null) patch.toString().toAnalyticsVersionStr() else ""
    val minorStr = minor.toString().padStart(2, '0').toLong().toString(2).toAnalyticsVersionStr()
    val majorStr = major.toString().padStart(2, '0').toLong().toString(2).toAnalyticsVersionStr()

    return "$majorStr$minorStr"
}

patchStr is never used

  1. In the method String.toAnalyticsVersionStr()

    private fun String.toAnalyticsVersionStr(): String {
    val num = this.toInt(2)
    return when (val num = this.toInt(2)) {
        in 0..25 -> {
            ('A' + num).toString()
        }
        in 26..51 -> {
            ('a' + num - 26).toString()
        }
        else -> ('0' + num - 52).toString()
    }
    }

    the local variable num is never used

  2. In the method String.toAnalyticsVersionStr()

    private fun String.toAnalyticsVersionStr(): String {
    val num = this.toInt(2)
    return when (val num = this.toInt(2)) {
        in 0..25 -> {
            ('A' + num).toString()
        }
        in 26..51 -> {
            ('a' + num - 26).toString()
        }
        else -> ('0' + num - 52).toString()
    }
    }

    There are two variables named num, thus causing variable shadowing

Relates to #107

TomerPacific commented 1 month ago

I'd like to fix this, if possible.

wissam-khalili commented 1 month ago

@adimiz1 - Can you please check this PR please ?

TomerPacific commented 1 month ago

@wissam-khalili - This issue can be closed as the PR has been approved and merged.