Two functions having the same implementation are suspicious. It might be that something else was intended. Or the duplication is intentional, which
becomes a maintenance burden.
class MyClass {
fun calculateCode(): String {
doTheThing()
doOtherThing()
return "done"
}
fun getStatus(): String { // Noncompliant: duplicates calculateCode
doTheThing()
doOtherThing()
return "done"
}
}
If the identical logic is intentional, the code should be refactored to avoid duplication. For example, by having both functions call the same
function or by having one implementation invoke the other.
class MyClass {
fun calculateCode(): String {
doTheThing()
doOtherThing()
return "done"
}
fun getStatus(): String = calculateCode() // Intent is clear
}
Exceptions
Methods with fewer than 2 statements are ignored.