actionview/lib/action_view/helpers/date_helper.rb

Summary

Maintainability
F
3 days
Test Coverage

File date_helper.rb has 459 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require "date"
require "action_view/helpers/tag_helper"
require "active_support/core_ext/array/extract_options"
require "active_support/core_ext/date/conversions"
require "active_support/core_ext/hash/slice"
Severity: Minor
Found in actionview/lib/action_view/helpers/date_helper.rb - About 7 hrs to fix

    Method distance_of_time_in_words has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
    Open

          def distance_of_time_in_words(from_time, to_time = 0, options = {})
            options = {
              scope: :'datetime.distance_in_words'
            }.merge!(options)
    
    
    Severity: Minor
    Found in actionview/lib/action_view/helpers/date_helper.rb - About 4 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

    Class DateTimeSelector has 31 methods (exceeds 20 allowed). Consider refactoring.
    Open

        class DateTimeSelector # :nodoc:
          include ActionView::Helpers::TagHelper
    
          DEFAULT_PREFIX = "date"
          POSITION = {
    Severity: Minor
    Found in actionview/lib/action_view/helpers/date_helper.rb - About 3 hrs to fix

      Method select_datetime has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
      Open

            def select_datetime
              order = date_order.dup
              order -= [:hour, :minute, :second]
              @options[:discard_year]   ||= true unless order.include?(:year)
              @options[:discard_month]  ||= true unless order.include?(:month)
      Severity: Minor
      Found in actionview/lib/action_view/helpers/date_helper.rb - About 3 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 distance_of_time_in_words has 48 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

            def distance_of_time_in_words(from_time, to_time = 0, options = {})
              options = {
                scope: :'datetime.distance_in_words'
              }.merge!(options)
      
      
      Severity: Minor
      Found in actionview/lib/action_view/helpers/date_helper.rb - About 1 hr to fix

        Method select_date has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

              def select_date
                order = date_order.dup
        
                @options[:discard_hour]     = true
                @options[:discard_minute]   = true
        Severity: Minor
        Found in actionview/lib/action_view/helpers/date_helper.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 separator has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

                def separator(type)
                  return "" if @options[:use_hidden]
        
                  case type
                  when :year, :month, :day
        Severity: Minor
        Found in actionview/lib/action_view/helpers/date_helper.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 build_options has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

                def build_options(selected, options = {})
                  options = {
                    leading_zeros: true, ampm: false, use_two_digit_numbers: false
                  }.merge!(options)
        
        
        Severity: Minor
        Found in actionview/lib/action_view/helpers/date_helper.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 select_year has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

              def select_year
                if !year || @datetime == 0
                  val = "1"
                  middle_year = Date.today.year
                else
        Severity: Minor
        Found in actionview/lib/action_view/helpers/date_helper.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 select_month has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

              def select_month
                if @options[:use_hidden] || @options[:discard_month]
                  build_hidden(:month, month || 1)
                else
                  month_options = []
        Severity: Minor
        Found in actionview/lib/action_view/helpers/date_helper.rb - About 25 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

        Method select_time has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

              def select_time
                order = []
        
                @options[:discard_month]    = true
                @options[:discard_year]     = true
        Severity: Minor
        Found in actionview/lib/action_view/helpers/date_helper.rb - About 25 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