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

Methods returns should not be invariant

    Details

    • Type: Code Smell Detection
    • Status: Active
    • Resolution: Unresolved
    • Labels:
      None
    • Message:
      Refactor this method to not always return the same value.
    • Highlighting:
      Hide

      Primary: method name
      Secondary: each return statement value

      Show
      Primary: method name Secondary: each return statement value
    • Default Severity:
      Blocker
    • Impact:
      High
    • Likelihood:
      High
    • Default Quality Profiles:
      Sonar way
    • Targeted languages:
      ABAP, C#, C++, Cobol, Flex, Objective-C, PHP, PL/I, PL/SQL, RPG, Swift, VB.Net, VB6
    • Covered Languages:
      C, Java, JavaScript, Python, TypeScript
    • Remediation Function:
      Linear
    • Linear Argument Description:
      Per number of return statements
    • Linear Factor:
      2min
    • Linear Offset:
      10min
    • Analysis Scope:
      Main Sources
    • Implementation details:
    • PVS-Studio:
      V3009

      Description

      When a method is designed to return an invariant value, it may be poor design, but it shouldn't adversely affect the outcome of your program. However, when it happens on all paths through the logic, it is surely a bug.

      This rule raises an issue when a method contains several return statements that all return the same value.

      Noncompliant Code Example

      int foo(int a) {
        int b = 12;
        if (a == 1) {
          return b;
        }
        return b;  // Noncompliant
      }
      

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                • Created:
                  Updated: