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
}
}