Boolean expression with five or more operands

ID

scala.maintainability.expression_too_complex

Severity

low

Remediation Complexity

medium

Remediation Risk

low

Remediation Effort

medium

Resource

Complexity

Language

Scala

Description

Reports a boolean expression that chains five or more operands with the same logical operator (&& or ||).

Rationale

A reader has to hold every operand and the whole truth table in mind at once to work out when the chain is true, and to know which operand a fix or a new requirement belongs to. Each extra operand also multiplies the combinations a test suite needs in order to exercise the condition, and a chain this long usually means several independent decisions have been fused into one.

The following code illustrates the pattern detected by this rule:

class ExpressionTooComplex {
  def canProceed(a: Boolean, b: Boolean, c: Boolean, d: Boolean, e: Boolean): Boolean = {
    // FLAGGED: Boolean expression with five or more operands
    a && b && c && d && e
  }
}

Remediation

Extract a coherent subset of the operands into a named local value or a small predicate method that states the intent, e.g. val isEligible = a && b && c followed by if (isEligible && d && e).

Configuration

This detector does not need any configuration.

© 2026 Xygeni. All rights reserved