activescaffold/active_scaffold

View on GitHub
lib/active_scaffold/finder.rb

Summary

Maintainability
D
2 days
Test Coverage
D
65%

File finder.rb has 483 lines of code (exceeds 250 allowed). Consider refactoring.
Open

module ActiveScaffold
  module Finder
    def self.like_operator
      @@like_operator ||= ::ActiveRecord::Base.connection.adapter_name.in?(%w[PostgreSQL PostGIS]) ? 'ILIKE' : 'LIKE'
    end
Severity: Minor
Found in lib/active_scaffold/finder.rb - About 7 hrs to fix

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

          def format_for_datetime(column, value)
            parts = Date._parse(value)
            if ActiveScaffold.js_framework == :jquery
              format = I18n.translate "time.formats.#{column.options[:format] || :picker}", :default => ''
            end
    Severity: Minor
    Found in lib/active_scaffold/finder.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 condition_for_column has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

          def condition_for_column(column, value, text_search = :full)
            like_pattern = like_pattern(text_search)
            value = value.with_indifferent_access if value.is_a? Hash
            if respond_to?("condition_for_#{column.name}_column")
              return send("condition_for_#{column.name}_column", column, value, like_pattern)
    Severity: Minor
    Found in lib/active_scaffold/finder.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 condition_value_for_datetime has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

          def condition_value_for_datetime(column, value, conversion = :to_time)
            return if value.nil? || value.blank?
            if value.is_a? Hash
              local_time_from_hash(value, conversion)
            elsif value.respond_to?(:strftime)
    Severity: Minor
    Found in lib/active_scaffold/finder.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 find_page has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

        def find_page(options = {})
          options.assert_valid_keys :sorting, :per_page, :page, :count_includes, :pagination, :select
          options[:per_page] ||= 999_999_999
          options[:page] ||= 1
    
    
    Severity: Minor
    Found in lib/active_scaffold/finder.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 condition_value_for_numeric has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

          def condition_value_for_numeric(column, value)
            return value if value.nil?
            value = column.number_to_native(value) if column.options[:format] && column.search_ui != :number
            case (column.search_ui || column.column.type)
            when :integer   then
    Severity: Minor
    Found in lib/active_scaffold/finder.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 parse_time_with_format has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

          def parse_time_with_format(value, format, offset)
            format.gsub!(/%-d|%-m|%_m/) { |s| s.gsub(/[-_]/, '') } # strptime fails with %-d, %-m, %_m
            en_value = I18n.locale == :en ? value : translate_days_and_months(value, format)
            time = Time.strptime(en_value, format)
            offset ? time : Time.zone.local_to_utc(time).in_time_zone
    Severity: Minor
    Found in lib/active_scaffold/finder.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 parse_date_with_format has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

          def parse_date_with_format(value, format_name)
            format = I18n.t("date.formats.#{format_name || :default}")
            format.gsub!(/%-d|%-m|%_m/) { |s| s.gsub(/[-_]/, '') } # strptime fails with %-d, %-m, %_m
            en_value = I18n.locale == :en ? value : translate_days_and_months(value, format)
            Date.strptime(en_value, format)
    Severity: Minor
    Found in lib/active_scaffold/finder.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 condition_for_search_ui has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

          def condition_for_search_ui(column, value, like_pattern, search_ui)
            case search_ui
            when :boolean, :checkbox
              ['%<search_sql>s = ?', column.column ? ActiveScaffold::Core.column_type_cast(value, column.column) : value]
            when :integer, :decimal, :float
    Severity: Minor
    Found in lib/active_scaffold/finder.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 condition_for_range has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

          def condition_for_range(column, value, like_pattern = nil)
            if !value.is_a?(Hash)
              if column.text?
                ["%<search_sql>s #{ActiveScaffold::Finder.like_operator} ?", like_pattern.sub('?', value)]
              else
    Severity: Minor
    Found in lib/active_scaffold/finder.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 condition_for_numeric has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

          def condition_for_numeric(column, value)
            if !value.is_a?(Hash)
              ['%<search_sql>s = ?', condition_value_for_numeric(column, value)]
            elsif ActiveScaffold::Finder::NULL_COMPARATORS.include?(value[:opt])
              condition_for_null_type(column, value[:opt])
    Severity: Minor
    Found in lib/active_scaffold/finder.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 sort_collection_by_column has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def sort_collection_by_column(collection, column, order)
          sorter = column.sort[:method]
          collection = collection.sort_by do |record|
            value = sorter.is_a?(Proc) ? record.instance_eval(&sorter) : record.instance_eval(sorter.to_s)
            value = '' if value.nil?
    Severity: Minor
    Found in lib/active_scaffold/finder.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 2 locations. Consider refactoring.
    Open

          rescue StandardError => e
            message = "Error parsing time from #{en_value}"
            message << " (#{value})" if en_value != value
            message << ", with format #{format}" if format
            Rails.logger.warn "#{message}:\n#{e.message}\n#{e.backtrace.join("\n")}"
    Severity: Minor
    Found in lib/active_scaffold/finder.rb and 1 other location - About 50 mins to fix
    lib/active_scaffold/finder.rb on lines 245..251

    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 43.

    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

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

          rescue StandardError => e
            message = "Error parsing date from #{en_value}"
            message << " (#{value})" if en_value != value
            message << ", with format #{format}" if format
            Rails.logger.warn "#{message}:\n#{e.message}\n#{e.backtrace.join("\n")}"
    Severity: Minor
    Found in lib/active_scaffold/finder.rb and 1 other location - About 50 mins to fix
    lib/active_scaffold/finder.rb on lines 258..264

    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 43.

    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