Fixed SonarCloud code smells

This commit is contained in:
Erik C. Thauvin 2023-10-26 21:13:46 -07:00
parent adaff5ec38
commit d700aa06df
6 changed files with 47 additions and 34 deletions

1
.idea/misc.xml generated
View file

@ -1,4 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" /> <component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="FrameworkDetectionExcludesConfiguration"> <component name="FrameworkDetectionExcludesConfiguration">

View file

@ -42,7 +42,6 @@ import org.slf4j.Logger
import java.io.* import java.io.*
import java.net.HttpURLConnection import java.net.HttpURLConnection
import java.net.URL import java.net.URL
import java.net.URLEncoder
import java.nio.file.Files import java.nio.file.Files
import java.nio.file.Paths import java.nio.file.Paths
import java.time.LocalDateTime import java.time.LocalDateTime
@ -125,16 +124,21 @@ object Utils {
*/ */
@JvmStatic @JvmStatic
fun String?.colorize(color: String): String { fun String?.colorize(color: String): String {
return if (isNullOrEmpty()) { return when {
isNullOrEmpty() -> {
"" ""
} else if (color == DEFAULT_COLOR) { }
color == DEFAULT_COLOR -> {
this this
} else if (Colors.BOLD == color || Colors.REVERSE == color) { }
Colors.BOLD == color || Colors.REVERSE == color -> {
color + this + color color + this + color
} else { }
else -> {
color + this + Colors.NORMAL color + this + Colors.NORMAL
} }
} }
}
/** /**
* Makes the given string cyan. * Makes the given string cyan.

View file

@ -129,7 +129,7 @@ class Ignore : AbstractCommand() {
} }
} }
if (ignored.size > 0) { if (ignored.isNotEmpty()) {
event.sendMessage("The following nicks are ignored:") event.sendMessage("The following nicks are ignored:")
event.sendList(ignored.sorted(), 8, isIndent = true) event.sendList(ignored.sorted(), 8, isIndent = true)
} else { } else {

View file

@ -85,19 +85,24 @@ class Tell(private val serialObject: String) : AbstractCommand() {
override fun commandResponse(channel: String, args: String, event: GenericMessageEvent) { override fun commandResponse(channel: String, args: String, event: GenericMessageEvent) {
if (isEnabled()) { if (isEnabled()) {
if (args.isBlank()) { when {
args.isBlank() -> {
helpResponse(channel, args, event) helpResponse(channel, args, event)
} else if (args.startsWith(View.VIEW_CMD)) { }
args.startsWith(View.VIEW_CMD) -> {
if (event.isChannelOp(channel) && "${View.VIEW_CMD} $TELL_ALL_KEYWORD" == args) { if (event.isChannelOp(channel) && "${View.VIEW_CMD} $TELL_ALL_KEYWORD" == args) {
viewAll(event) viewAll(event)
} else { } else {
viewMessages(event) viewMessages(event)
} }
} else if (args.startsWith("$TELL_DEL_KEYWORD ")) { }
args.startsWith("$TELL_DEL_KEYWORD ") -> {
deleteMessage(channel, args, event) deleteMessage(channel, args, event)
} else { }
else -> {
newMessage(channel, args, event) newMessage(channel, args, event)
} }
}
if (clean()) { if (clean()) {
save() save()
} }

View file

@ -141,7 +141,7 @@ class FeedsManager private constructor() {
.append("\"><b>") .append("\"><b>")
.append(channel) .append(channel)
.append("</b></a>") .append("</b></a>")
if (comments.size > 0) { if (comments.isNotEmpty()) {
buff.append(" <br/><br/>") buff.append(" <br/><br/>")
for (j in comments.indices) { for (j in comments.indices) {
if (j > 0) { if (j > 0) {

View file

@ -74,21 +74,26 @@ class CurrencyConverter : AbstractModule() {
override fun commandResponse(channel: String, cmd: String, args: String, event: GenericMessageEvent) { override fun commandResponse(channel: String, cmd: String, args: String, event: GenericMessageEvent) {
reload(properties[API_KEY_PROP]) reload(properties[API_KEY_PROP])
if (SYMBOLS.isEmpty()) { when {
SYMBOLS.isEmpty() -> {
event.respond(EMPTY_SYMBOLS_TABLE) event.respond(EMPTY_SYMBOLS_TABLE)
} else if (args.matches("\\d+([,\\d]+)?(\\.\\d+)? [a-zA-Z]{3}+ (to|in) [a-zA-Z]{3}+".toRegex())) { }
args.matches("\\d+([,\\d]+)?(\\.\\d+)? [a-zA-Z]{3}+ (to|in) [a-zA-Z]{3}+".toRegex()) -> {
val msg = convertCurrency(properties[API_KEY_PROP], args) val msg = convertCurrency(properties[API_KEY_PROP], args)
event.respond(msg.msg) event.respond(msg.msg)
if (msg.isError) { if (msg.isError) {
helpResponse(event) helpResponse(event)
} }
} else if (args.contains(CODES_KEYWORD)) { }
args.contains(CODES_KEYWORD) -> {
event.sendMessage("The supported currency codes are:") event.sendMessage("The supported currency codes are:")
event.sendList(SYMBOLS.keys.toList(), 11, isIndent = true) event.sendList(SYMBOLS.keys.toList(), 11, isIndent = true)
} else { }
else -> {
helpResponse(event) helpResponse(event)
} }
} }
}
override fun helpResponse(event: GenericMessageEvent): Boolean { override fun helpResponse(event: GenericMessageEvent): Boolean {
reload(properties[API_KEY_PROP]) reload(properties[API_KEY_PROP])