Showing 25 of 25 total issues
Method to_s
has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring. Open
def self.to_s(first = nil, last = nil, month_fmt = '%b %Y', date_fmt = default_date_format, time_fmt = nil)
time_fmt ||= date_fmt + ' %H:%M'
is_date = first.is_a?(Date) || last.is_a?(Date)
fmt = is_date ? date_fmt : time_fmt
if first && last
- 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 choose_dates
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
def choose_dates
# Not multiple dates - just return the From date.
return [@from] unless @multiple_dates
# Multiple dates - return the array, adjusted as per input
- 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 to_s
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
def to_s
if first_datetime == last_datetime
"on #{first_datetime}#{first_datetime == first_datetime.beginning_of_day ? "" : " at #{first_datetime.strftime("%I:%M %p")}"}"
elsif first_datetime == first_datetime.beginning_of_month && last_datetime == last_datetime.end_of_month
if first_datetime.month == last_datetime.month
- 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 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
Method initialize
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
def initialize(weekdays)
@weekdays = {
sun: false,
mon: false,
tue: false,
Method to_s
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
def to_s
single_date_intervals, multiple_dates_intervals = intervals.partition { |i| i.first_datetime == i.last_datetime}
patterns_strings = if multiple_dates_intervals.empty?
single_date_intervals.map(&:to_s)
else
- 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 from_patterns
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
def self.from_patterns(patterns)
date_groups = []
Array.wrap(patterns).each do |pattern|
if pattern.frequency.unit == :weeks
weekdays = pattern.intervals.map { |i| i.first_datetime.wday }.each_with_object({}) do |wday, hash|
Method calendar_tag
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def calendar_tag(name, value = Timely.current_date, *args)
options = args.extract_options!
if value.respond_to?(:day)
value = value.respond_to?(:to_fs) ? value.to_fs(:calendar) : value.to_s(:calendar)
- 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 to_date
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def to_date(fmt = nil)
if fmt
fmt = Date::DATE_FORMATS[fmt] if fmt.is_a?(Symbol) && defined?(Date::DATE_FORMATS)
parsed = ::Date._strptime(self, fmt)
parsed[:year] = parsed[:year] + 2000 if parsed[:year] < 1000
- 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 to_s
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
def to_s
single_date_intervals, multiple_dates_intervals = intervals.partition { |i| i.first_datetime == i.last_datetime}
patterns_strings = if multiple_dates_intervals.empty?
single_date_intervals.map(&:to_s)
else
Method choose_dates
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
def choose_dates
# Not multiple dates - just return the From date.
return [@from] unless @multiple_dates
# Multiple dates - return the array, adjusted as per input
Method between?
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def between?(from, to)
from = from.to_date if from && !from.is_a?(Date)
to = to.to_date if to && !to.is_a?(Date)
if from && to
- 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 to_s
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def self.to_s(first = nil, last = nil, month_fmt = '%b %Y', date_fmt = default_date_format, time_fmt = nil)
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 fix_frequency
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def fix_frequency
return unless frequency.duration > 1.month
if frequency.duration < 12.months
if intervals.all? { |i| i.first_datetime.day == i.last_datetime.day }
frequency.duration = frequency.units[:months].months
- 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 join
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def join(other)
return nil unless self.frequency == other.frequency
expanded_datetimes = self.datetimes.map { |datetimes_within_an_interval|
back_one = datetimes_within_an_interval.first - frequency.duration
- 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 to_s
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def to_s
"every " + duration.parts.
reduce(::Hash.new(0)) { |h,(l,r)| h[l] += r; h }.
sort_by {|unit, _ | [:years, :months, :days, :minutes, :seconds].index(unit)}.
map {|unit, val| "#{val} #{val == 1 ? unit.to_s.chop : unit.to_s}" if val.nonzero?}.compact.
- 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 validate
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def validate
raise DateChooserException, 'A Start Date is required' unless @from
raise DateChooserException, 'Start Date is after End Date' if @multiple_dates && @to && @from > @to
@to ||= @from if @multiple_dates
- 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"