Uploaded image for project: 'Rules Repository'
  1. Rules Repository
  2. RSPEC-3502

Methods in the same class should not have the same body

    XMLWordPrintable

    Details

    • Type: Code Smell Detection
    • Status: Closed
    • Resolution: Duplicate
    • Labels:
    • Message:
      Hide
      * Return the results of "xxx" instead.
      * Call "xxx" instead.
      Show
      * Return the results of "xxx" instead. * Call "xxx" instead.
    • List of parameters:
      • primary: method name
      • secondary: method body
        • message: duplicates body of "xxx"
    • Default Severity:
      Major
    • Impact:
      Low
    • Likelihood:
      High
    • Default Quality Profiles:
      Sonar way
    • Targeted languages:
      C#, C, C++, CSS, Flex, Java, JavaScript, Objective-C, PHP, Python, Swift, VB.Net, VB6
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      5min

      Description

      Having two methods in the same class with the same body is suspicious and potentially confusing. If it is due to a bad copy/paste, it should be fixed. If it's on purpose, it is clearer for the second method to simply call the first.

      Noncompliant Code Example

      public void doTheThing() {
        this.x = 4;
      }
      
      public void doTheOtherThing {  // Noncompliant
        this.x = 4;
      }
      

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            ann.campbell.2 Ann Campbell
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: