opf/openproject

View on GitHub
lib/chronic_duration.rb

Summary

Maintainability
D
2 days
Test Coverage

Method output has a Cognitive Complexity of 51 (exceeds 5 allowed). Consider refactoring.
Open

  def output(seconds, opts = {})
    int = seconds.to_i
    seconds = int if seconds - int == 0 # if seconds end with .0

    opts[:format] ||= :default
Severity: Minor
Found in lib/chronic_duration.rb - About 7 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 output has 105 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def output(seconds, opts = {})
    int = seconds.to_i
    seconds = int if seconds - int == 0 # if seconds end with .0

    opts[:format] ||= :default
Severity: Major
Found in lib/chronic_duration.rb - About 4 hrs to fix

    File chronic_duration.rb has 262 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    module ChronicDuration
      extend self
    
      class DurationParseError < StandardError
      end
    Severity: Minor
    Found in lib/chronic_duration.rb - About 2 hrs to fix

      Method mappings has 35 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def mappings
          {
            "seconds" => "seconds",
            "second" => "seconds",
            "secs" => "seconds",
      Severity: Minor
      Found in lib/chronic_duration.rb - About 1 hr to fix

        Avoid deeply nested control flow statements.
        Open

                    if days >= days_per_week
                      weeks = (days / days_per_week).to_i
                      days = (days % days_per_week).to_i
                      if weeks >= FULL_WEEKS_PER_MONTH
                        months = (weeks / FULL_WEEKS_PER_MONTH).to_i
        Severity: Major
        Found in lib/chronic_duration.rb - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                    elsif days >= days_per_month
                      months = (days / days_per_month).to_i
                      days = (days % days_per_month).to_i
          Severity: Major
          Found in lib/chronic_duration.rb - About 45 mins to fix

            Method filter_through_white_list has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

              def filter_through_white_list(string)
                res = []
                string.split.each do |word|
                  if word&.match?(float_matcher)
                    res << word.strip
            Severity: Minor
            Found in lib/chronic_duration.rb - About 45 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

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

              def filter_by_type(string)
                chrono_units_list = duration_units_list.reject { |v| v == "weeks" }
            
                if string.delete(" ")&.match?(time_matcher)
                  res = []
            Severity: Minor
            Found in lib/chronic_duration.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

            There are no issues that match your filters.

            Category
            Status