twitter/twitter-cldr-rb

View on GitHub
lib/twitter_cldr/formatters/calendars/date_time_formatter.rb

Summary

Maintainability
C
1 day
Test Coverage

File date_time_formatter.rb has 304 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'tzinfo'

module TwitterCldr
  module Formatters
    class DateTimeFormatter < Formatter
Severity: Minor
Found in lib/twitter_cldr/formatters/calendars/date_time_formatter.rb - About 3 hrs to fix

    Class DateTimeFormatter has 25 methods (exceeds 20 allowed). Consider refactoring.
    Open

        class DateTimeFormatter < Formatter
    
          WEEKDAY_KEYS = [:sun, :mon, :tue, :wed, :thu, :fri, :sat].freeze
    
          METHODS = { # ignoring u, l, g, j, A
    Severity: Minor
    Found in lib/twitter_cldr/formatters/calendars/date_time_formatter.rb - About 2 hrs to fix

      Method hour has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

            def hour(time, pattern, length, options = {})
              hour = time.hour
              hour = case pattern[0, 1]
                when 'h' # [1-12]
                  hour > 12 ? (hour - 12) : (hour == 0 ? 12 : hour)
      Severity: Minor
      Found in lib/twitter_cldr/formatters/calendars/date_time_formatter.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 week_fields_for has 38 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

            def week_fields_for(date)
              week_data_cache[date] ||= begin
                eyear = date.year
                day_of_week = date.wday + 1
                day_of_year = date.yday
      Severity: Minor
      Found in lib/twitter_cldr/formatters/calendars/date_time_formatter.rb - About 1 hr to fix

        Method era has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

              def era(date, pattern, length, options = {})
                choices = case length
                  when 0
                    ["", ""]
                  when 1..3
        Severity: Minor
        Found in lib/twitter_cldr/formatters/calendars/date_time_formatter.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

        There are no issues that match your filters.

        Category
        Status