newmen/versatile-diamond

View on GitHub
analyzer/lib/tools/dimension.rb

Summary

Maintainability
C
1 day
Test Coverage

Method convert_rate has a Cognitive Complexity of 43 (exceeds 5 allowed). Consider refactoring.
Open

        def convert_rate(value, gases_num, dimension = nil)
          return 0 if value == 0

          dimension ||= @rate
          syntax_error('.is_not_set') unless dimension
Severity: Minor
Found in analyzer/lib/tools/dimension.rb - About 6 hrs 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

Method convert_rate has 63 lines of code (exceeds 25 allowed). Consider refactoring.
Open

        def convert_rate(value, gases_num, dimension = nil)
          return 0 if value == 0

          dimension ||= @rate
          syntax_error('.is_not_set') unless dimension
Severity: Major
Found in analyzer/lib/tools/dimension.rb - About 2 hrs to fix

    Consider simplifying this complex logical expression.
    Open

              if gases_num > 0 || dimension != DEFAULT_RATE
                _, dividend, _, divisor =
                  dimension.gsub(/\(|\)/, '|').gsub(/\s/, '').
                    scan(%r{\A(\|)?([^\/]+)\1?/(\|)?(.+?)\3?\Z}).first
    
    
    Severity: Major
    Found in analyzer/lib/tools/dimension.rb - About 40 mins to fix

      Method convert has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

              def convert(var, value, convertable_dimension = nil)
                convertable_dimension && convertable_dimension.strip!
      
                current_dimension = instance_variable_get("@#{var}".to_sym)
                unless current_dimension || convertable_dimension
      Severity: Minor
      Found in analyzer/lib/tools/dimension.rb - About 35 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

      There are no issues that match your filters.

      Category
      Status