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
- 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 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
File chronic_duration.rb
has 262 lines of code (exceeds 250 allowed). Consider refactoring. Open
module ChronicDuration
extend self
class DurationParseError < StandardError
end
Method mappings
has 35 lines of code (exceeds 25 allowed). Consider refactoring. Open
def mappings
{
"seconds" => "seconds",
"second" => "seconds",
"secs" => "seconds",
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
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
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
- 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 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 = []
- 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"