sealink/timely

View on GitHub
lib/timely/temporal_patterns/finder.rb

Summary

Maintainability
B
4 hrs
Test Coverage

Method find_patterns has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
Open

        def find_patterns(datetimes, options = {})
          frequency_patterns = []

          return [] if datetimes.blank?

Severity: Minor
Found in lib/timely/temporal_patterns/finder.rb - About 2 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

Consider simplifying this complex logical expression.
Open

            if best_fit.nil? ||
                (best_fit[:intervals].count < pattern_hash[:intervals].count) ||
                (best_fit[:intervals].count == pattern_hash[:intervals].count && (best_fit[:ranges].count > pattern_hash[:ranges].count ||
                (best_fit[:ranges].count == pattern_hash[:ranges].count && best_fit[:frequency] < pattern_hash[:frequency])))
              best_fit = pattern_hash
Severity: Major
Found in lib/timely/temporal_patterns/finder.rb - About 40 mins to fix

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

            def frequency_pattern(datetimes, frequency)
              return nil if datetimes.blank? || frequency.to_f < 1 || ((datetimes.first + frequency) > datetimes.last)
              pattern_intervals = []
              pattern_ranges = []
              intervals = condition_intervals(datetimes) do |current_date, next_date|
    Severity: Minor
    Found in lib/timely/temporal_patterns/finder.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

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

            def frequency_patterns(datetimes)
              return [] if datetimes.blank?
              datetimes = datetimes.clone
              patterns = {}
              while (current_datetime = datetimes.pop)
    Severity: Minor
    Found in lib/timely/temporal_patterns/finder.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

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

            def condition_intervals(datetimes, &block)
              return [] if datetimes.blank? || !block_given?
              datetimes = datetimes.clone
              current_datetime = first_datetime = datetimes.shift
              last_datetime = nil
    Severity: Minor
    Found in lib/timely/temporal_patterns/finder.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

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

            def best_pattern(frequency_patterns)
              best_fit = nil
              frequency_patterns.each do |pattern_hash|
                if best_fit.nil? ||
                    (best_fit[:intervals].count < pattern_hash[:intervals].count) ||
    Severity: Minor
    Found in lib/timely/temporal_patterns/finder.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