When two functions have the same implementation, either it was a mistake - something else was intended - or the duplication was intentional, but may be confusing to maintainers. In the latter case, the code should be refactored. Numerical and string literals are not taken into account.

Noncompliant Code Example

class MyClass {
  private readonly CODE = "bounteous";

  public calculateCode(): string {
    doTheThing();
    doOtherThing();
    return this.CODE;
  }

  public getName(): string {  // Noncompliant
    doTheThing();
    doOtherThing();
    return this.CODE;
  }
}

Compliant Solution

class MyClass {
  private readonly CODE = "bounteous";

  public calculateCode(): string {
    doTheThing();
    doOtherThing();
    return this.CODE;
  }

  public getName(): string {
    return this.calculateCode();
  }
}

Exceptions

Functions with fewer than 3 lines are ignored.