Method declares two or more Boolean parameters
ID |
apex.maintainability.multiple_bool_parameters |
Severity |
info |
Remediation Complexity |
medium |
Remediation Risk |
medium |
Remediation Effort |
medium |
Resource |
Api Design |
Language |
Apex |
Rationale
Apex has no named arguments, so a call reads post(true, false) and says nothing about which flag is which. Two Boolean parameters of the same type sit next to each other with nothing to stop them being swapped, and a swapped pair compiles, deploys and silently does the opposite of what was meant. The reader is forced to open the declaration to understand any call site.
The following code illustrates the pattern detected by this rule:
public class BoolParams {
// FLAGGED: Method declares two or more Boolean parameters
public void post(Boolean draft, Boolean notify) {
System.debug(draft);
}
// FLAGGED: Method declares two or more Boolean parameters
public static void sync(Id recordId, Boolean force, String source, Boolean async) {
System.debug(recordId);
}
public void postDraft(Boolean notify) {
System.debug(notify);
}
public void update(Id recordId, String source) {
System.debug(recordId);
}
}