app/models/periods.rb

Summary

Maintainability
A
55 mins
Test Coverage
A
100%

Cyclomatic complexity for detect is too high. [7/6]
Open

  def self.detect(dhis2Period)
    return QUARTERLY if dhis2Period[4] == "Q" && dhis2Period.size == 6

    return SIX_MONTHLY if dhis2Period.include?("S")

Severity: Minor
Found in app/models/periods.rb by rubocop

This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.

Avoid too many return statements within this method.
Open

    return FINANCIAL_JULY if dhis2Period.include?("July")
Severity: Major
Found in app/models/periods.rb - About 30 mins to fix

    Method detect has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

      def self.detect(dhis2Period)
        return QUARTERLY if dhis2Period[4] == "Q" && dhis2Period.size == 6
    
        return SIX_MONTHLY if dhis2Period.include?("S")
    
    
    Severity: Minor
    Found in app/models/periods.rb - About 25 mins to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Use snake_case for variable names.
    Open

      def self.detect(dhis2Period)
    Severity: Minor
    Found in app/models/periods.rb by rubocop

    This cop makes sure that all variables use the configured style, snake_case or camelCase, for their names.

    Example: EnforcedStyle: snake_case (default)

    # bad
    fooBar = 1
    
    # good
    foo_bar = 1

    Example: EnforcedStyle: camelCase

    # bad
    foo_bar = 1
    
    # good
    fooBar = 1

    Only use lowercase characters for method parameter.
    Open

      def self.detect(dhis2Period)
    Severity: Minor
    Found in app/models/periods.rb by rubocop

    This cop checks method parameter names for how descriptive they are. It is highly configurable.

    The MinNameLength config option takes an integer. It represents the minimum amount of characters the name must be. Its default is 3. The AllowNamesEndingInNumbers config option takes a boolean. When set to false, this cop will register offenses for names ending with numbers. Its default is false. The AllowedNames config option takes an array of whitelisted names that will never register an offense. The ForbiddenNames config option takes an array of blacklisted names that will always register an offense.

    Example:

    # bad
    def bar(varOne, varTwo)
      varOne + varTwo
    end
    
    # With `AllowNamesEndingInNumbers` set to false
    def foo(num1, num2)
      num1 * num2
    end
    
    # With `MinArgNameLength` set to number greater than 1
    def baz(a, b, c)
      do_stuff(a, b, c)
    end
    
    # good
    def bar(thud, fred)
      thud + fred
    end
    
    def foo(speed, distance)
      speed * distance
    end
    
    def baz(age_a, height_b, gender_c)
      do_stuff(age_a, height_b, gender_c)
    end

    There are no issues that match your filters.

    Category
    Status