Sonarqube allows only 7 parameters for the function. I have a function that forms the string with 8 parameters.
fun example(
context: Context,
a: Int,
b: Int,
c: String,
d: Int,
e: String,
list: List<String>,
dat: String
) {
a = d+b
var f = a+b+d
if (list >0){
f = f+ "example"
}
return c+ e + f + dat
}
To make this function have only 7 parameters. I split the function by removing last parameter dat
but in order to calculate dat
variable I need b
and d
variables value also. So after function returns I need the value of b
and d
to evaluate dat
and later concat dat
to function return. Like below
fun example(
context: Context,
a: Int,
b: Int,
c: String,
d: Int,
e: String,
list: List<String>
) {
a = d+b
var f = a+b+d
if (list >0){
f = f+ "example"
}
return c+ e + f
}
// i call it like below
example(context, 1, 1, "c", 1, "e", listOf('list1', 'list2')) + exampleConcat("dat text")
fun exampleConcat(dat: String) {
val t = d + b + dat // here i need the latest value of 'd' and 'b'
return t
}
How do i get d
and b
latest value becoz after function returns these local variable will be destroyed?. How to make this function efficient by passing 7 arguments.