Scala

Scala

Made by DeepSource

Consider rewriting this if condition as case's entry guard SC-R1023

Anti-pattern
Minor

When pattern matching, cases allow you to specify conditions that act as entry guards. Controller then enters into the body of these cases only if these conditions satisfy. In scenarios where the body of a case is wrapped in an if condition, consider moving this if condition and rewriting it as an entry guard. Doing so improves the overall readability of the code.

Bad Practice

Users.getDetails(emailId) match {
  case Some(details) =>
    if (details.isAdmin) {
      // ...
    }

  case None =>
}

Recommended

Users.getDetails(emailId) match {
  case Some(details) if details.isAdmin =>
    // ...

  case None =>
}