lib/timely/date_range.rb
Method to_s
has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring. Open
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 to_s
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
Open
def self.to_s(first = nil, last = nil, month_fmt = '%b %Y', date_fmt = default_date_format, time_fmt = nil)
Method validate_range
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
Open
def self.validate_range(first, last)
raise ArgumentError, 'Date range missing start date' if first.nil?
raise ArgumentError, 'Date range missing end date' if last.nil?
raise ArgumentError, 'Start date is not a date' unless first.is_a? Date
raise ArgumentError, 'End date is not a date' unless last.is_a? 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"