activescaffold/active_scaffold

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

Summary

Maintainability
D
2 days
Test Coverage
F
55%

File list_column_helpers.rb has 391 lines of code (exceeds 250 allowed). Consider refactoring.
Open

module ActiveScaffold
  module Helpers
    # Helpers that assist with the rendering of a List Column
    module ListColumnHelpers
      def get_column_value(record, column)
Severity: Minor
Found in lib/active_scaffold/helpers/list_column_helpers.rb - About 5 hrs to fix

    Method format_column_value has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
    Open

          def format_column_value(record, column, value = nil)
            value ||= record.send(column.name) unless record.nil?
            if column.association.nil?
              form_ui_options = column.form_ui_options || column.options if FORM_UI_WITH_OPTIONS.include?(column.form_ui)
              if form_ui_options&.dig(:options)
    Severity: Minor
    Found in lib/active_scaffold/helpers/list_column_helpers.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

    Method render_list_column has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

          def render_list_column(text, column, record)
            if column.link && !skip_action_link?(column.link, record)
              link = column.link
              associated = record.send(column.association.name) if column.association
              authorized = link.action.nil?
    Severity: Minor
    Found in lib/active_scaffold/helpers/list_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 get_column_value has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

          def get_column_value(record, column)
            record = record.send(column.delegated_association.name) if column.delegated_association
            if record
              method, list_ui = get_column_method(record, column)
              value =
    Severity: Minor
    Found in lib/active_scaffold/helpers/list_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 format_collection_association_value has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

          def format_collection_association_value(value, column, label_method, size)
            associated_limit = column.associated_limit
            if associated_limit.nil?
              firsts = value.collect(&label_method)
              safe_join firsts, association_join_text(column)
    Severity: Minor
    Found in lib/active_scaffold/helpers/list_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 inplace_edit_data has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

          def inplace_edit_data(column)
            data = {}
            data[:ie_url] = url_for(params_for(:action => 'update_column', :column => column.name, :id => '__id__'))
            data[:ie_cancel_text] = column.options[:cancel_text] || as_(:cancel)
            data[:ie_loading_text] = column.options[:loading_text] || as_(:loading)
    Severity: Minor
    Found in lib/active_scaffold/helpers/list_column_helpers.rb - About 55 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 column_heading_value has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

          def column_heading_value(column, sorting, sort_direction)
            if column.name == :as_marked
              mark_column_heading
            elsif column.sortable?
              options = {:id => nil, :class => 'as_sort',
    Severity: Minor
    Found in lib/active_scaffold/helpers/list_column_helpers.rb - About 55 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 format_number_value has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

          def format_number_value(value, options = {})
            if value
              value =
                case options[:format]
                when :size
    Severity: Minor
    Found in lib/active_scaffold/helpers/list_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 cache_association has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

          def cache_association(association, column, size)
            associated_limit = column.associated_limit
            # we are not using eager loading, cache firsts records in order not to query the database for whole association in a future
            if associated_limit.nil?
              logger.warn "ActiveScaffold: Enable eager loading for #{column.name} association to reduce SQL queries"
    Severity: Minor
    Found in lib/active_scaffold/helpers/list_column_helpers.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

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

          def get_column_method(record, column)
            # check for an override helper
            ActiveScaffold::Registry.cache :column_methods, column.cache_key do
              if (method = column_override(column))
                # we only pass the record as the argument. we previously also passed the formatted_value,
    Severity: Minor
    Found in lib/active_scaffold/helpers/list_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

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

          def inplace_edit_control(column)
            return unless inplace_edit?(active_scaffold_config.model, column) && inplace_edit_cloning?(column)
            unless ActiveScaffold.threadsafe
              column = column.dup
              column.options = column.options.dup
    Severity: Minor
    Found in lib/active_scaffold/helpers/list_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

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

          def active_scaffold_column_boolean(record, column, ui_options: column.options)
            value = record.send(column.name)
            if value.nil? && ui_options[:include_blank]
              value = ui_options[:include_blank]
              value.is_a?(Symbol) ? as_(value) : value
    Severity: Minor
    Found in lib/active_scaffold/helpers/list_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/list_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/search_column_helpers.rb on lines 50..53

    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