farski/periodic

View on GitHub

Showing 3 of 5 total issues

Method sanitize_formatted_string has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
Open

    def self.sanitize_formatted_string(string)
      if string.match(/:/) && !string.match(/[a-zA-Z ]/)
        # add leading zeros where missing...
        string.gsub!(/!(\d):/, '!0\1:')
        string.gsub!(/^(\d):/, '0\1:')
Severity: Minor
Found in lib/periodic/duration.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

Method format has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

      def format(format = '%y:%d:%h:%m:%s', precision = nil)
        string, nondirective_units, values, smallest_unit_directive = format, [], Hash.new, nil

        Periodic::Duration::Units::TIME_ORDER.reverse.each_with_index do |unit, i|
          if format =~ Periodic::Duration::Units::TIME[unit][:directive]
Severity: Minor
Found in lib/periodic/duration.rb - About 1 hr 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 extract_time_parts_from_text has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

      def extract_time_parts_from_text
        normalize_string
        units = { :s => :seconds, :m => :minutes, :h => :hours, :d => :days, :w => :weeks, :n => :months, :y => :years, :a => :decades, :c => :centuries, :b => :millennia }
        @string.split(' ').each { |part| @time_parts[part.match(/([a-z])/) ? units[part.match(/([a-z])/)[1].to_sym] : @bias] = (@time_parts[part.match(/([a-z])/) ? units[part.match(/([a-z])/)[1].to_sym] : @bias]||0) + part.to_f }
      end
Severity: Minor
Found in lib/periodic/parser.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

Severity
Category
Status
Source
Language