Two methods having the same implementation are suspicious. It might be that something else was intended. Or the duplication is intentional, which
becomes a maintenance burden.
private String code = 'secret';
public String calculateCode() {
doTheThing();
return code;
}
public String getName() { // Noncompliant: duplicates calculateCode
doTheThing();
return code;
}
If the identical logic is intentional, the code should be refactored to avoid duplication. For example, by having both methods call the same method
or by having one implementation invoke the other.
private String code = 'secret';
public String getCode() {
doTheThing();
return code;
}
public String getName() { // Intent is clear
return getCode();
}
Exceptions
Methods that are not accessors (getters and setters), with fewer than 2 statements are ignored.