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?
- Read upRead up
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
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|
- Read upRead up
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)
- Read upRead up
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
- Read upRead up
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) ||
- Read upRead up
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"