activescaffold/active_scaffold

View on GitHub
lib/active_scaffold/helpers/search_column_helpers.rb

Summary

Maintainability
D
2 days
Test Coverage
F
23%

File search_column_helpers.rb has 328 lines of code (exceeds 250 allowed). Consider refactoring.
Open

module ActiveScaffold
  module Helpers
    # Helpers that assist with the rendering of a Form Column
    module SearchColumnHelpers
      # This method decides which input to use for the given column.
Severity: Minor
Found in lib/active_scaffold/helpers/search_column_helpers.rb - About 3 hrs to fix

    Method active_scaffold_search_for has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
    Open

          def active_scaffold_search_for(column, options = nil)
            options ||= active_scaffold_search_options(column)
            search_columns = active_scaffold_config.field_search.columns.visible_columns_names
            options = update_columns_options(column, nil, options, form_columns: search_columns, url_params: {form_action: :field_search})
            record = options[:object]
    Severity: Minor
    Found in lib/active_scaffold/helpers/search_column_helpers.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 active_scaffold_search_select has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
    Open

          def active_scaffold_search_select(column, html_options, options = {}, ui_options: column.options)
            record = html_options.delete(:object)
            associated = html_options.delete :value
            if column.association
              associated = associated.is_a?(Array) ? associated.map(&:to_i) : associated.to_i unless associated.nil?
    Severity: Minor
    Found in lib/active_scaffold/helpers/search_column_helpers.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 visibles_and_hiddens has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

          def visibles_and_hiddens(search_config)
            visibles = []
            hiddens = []
            search_config.columns.each_column do |column|
              next unless column.search_sql
    Severity: Minor
    Found in lib/active_scaffold/helpers/search_column_helpers.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 active_scaffold_search_range has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

          def active_scaffold_search_range(column, options, input_method = :text_field_tag, input_options = {}, ui_options: column.options)
            opt_value, from_value, to_value = field_search_params_range_values(column)
    
            select_options = active_scaffold_search_range_comparator_options(column, ui_options: ui_options)
            text_field_size = active_scaffold_search_range_string?(column) ? 15 : 10
    Severity: Minor
    Found in lib/active_scaffold/helpers/search_column_helpers.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 active_scaffold_search_for has 29 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

          def active_scaffold_search_for(column, options = nil)
            options ||= active_scaffold_search_options(column)
            search_columns = active_scaffold_config.field_search.columns.visible_columns_names
            options = update_columns_options(column, nil, options, form_columns: search_columns, url_params: {form_action: :field_search})
            record = options[:object]
    Severity: Minor
    Found in lib/active_scaffold/helpers/search_column_helpers.rb - About 1 hr to fix

      Method active_scaffold_search_select has 27 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

            def active_scaffold_search_select(column, html_options, options = {}, ui_options: column.options)
              record = html_options.delete(:object)
              associated = html_options.delete :value
              if column.association
                associated = associated.is_a?(Array) ? associated.map(&:to_i) : associated.to_i unless associated.nil?
      Severity: Minor
      Found in lib/active_scaffold/helpers/search_column_helpers.rb - About 1 hr to fix

        Method active_scaffold_search_datetime_field has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

              def active_scaffold_search_datetime_field(column, options, current_search, name, ui_options: column.options)
                options = ui_options.merge(options)
                type = "#{'date' unless options[:discard_date]}#{'time' unless options[:discard_time]}"
                field_name = "#{options[:name]}[#{name}]"
                if options[:use_select]
        Severity: Minor
        Found in lib/active_scaffold/helpers/search_column_helpers.rb - About 45 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 active_scaffold_search_multi_select has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

              def active_scaffold_search_multi_select(column, options, ui_options: column.options)
                record = options.delete(:object)
                associated = options.delete :value
                associated = [associated].compact unless associated.is_a? Array
        
        
        Severity: Minor
        Found in lib/active_scaffold/helpers/search_column_helpers.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

        Similar blocks of code found in 4 locations. Consider refactoring.
        Open

              rescue StandardError => e
                logger.error "#{e.class.name}: #{e.message} -- on the ActiveScaffold column = :#{column.name} in #{controller.class}"
                raise e
              end
        Severity: Minor
        Found in lib/active_scaffold/helpers/search_column_helpers.rb and 3 other locations - About 15 mins to fix
        lib/active_scaffold/bridges/record_select/helpers.rb on lines 81..84
        lib/active_scaffold/helpers/form_column_helpers.rb on lines 49..52
        lib/active_scaffold/helpers/list_column_helpers.rb on lines 60..63

        Duplicated Code

        Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

        Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

        When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

        Tuning

        This issue has a mass of 26.

        We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

        The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

        If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

        See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

        Refactorings

        Further Reading

        There are no issues that match your filters.

        Category
        Status