Czar
12/09/2019, 7:12 AMclass MyEntity {
val id: Long? = null
var prop1: String? = null
var prop2: String? = null
// ...
var propN: String? = null
}
and an update command:
class UpdateEntityCommand {
val myEntityId: Long
var prop1: String? = null
var prop2: String? = null
// ...
var propN: String? = null
}
the handler should only change property of the entity if corresponding property of the command is not null
:
class MyHandler(private val repo: MyEntityRepository) {
fun handle(command: UpdateEntityCommand) {
with(repository.getOne(command.myEntityId)) {
// (1)
if (command.prop1 != null) prop1 = command.prop1
// (2)
command.prop2?.let { prop2 = it }
// (3)
ifNotNull(command.propN) { propN = it }
}
}
}
If all the properties are set using method (1) or (3), detekt is happy, if method (2) is used, detekt is complaining about "ComplexMethod"
Should I report this to the issue tracker, or is it as it should be? If the latter, I wonder why?Brais Gabin
12/09/2019, 12:24 PMifNotNull
an standard function? If so, it should be the same too.Czar
12/10/2019, 7:18 AMinline fun <T : Any, R> ifNotNull(input: T?, block: (T) -> R): R? = input?.let(block)