ManageIQ/manageiq-ui-classic

View on GitHub
app/controllers/application_controller/filter/expression.rb

Summary

Maintainability
F
1 wk
Test Coverage
F
40%

Method update_from_expression_editor has a Cognitive Complexity of 271 (exceeds 5 allowed). Consider refactoring.
Open

    def update_from_expression_editor(params)
      if params[:chosen_typ] && params[:chosen_typ] != exp_typ
        change_exp_typ(params[:chosen_typ])
      else
        case exp_typ
Severity: Minor
Found in app/controllers/application_controller/filter/expression.rb - About 5 days 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

Cyclomatic complexity for update_from_expression_editor is too high. [95/11]
Open

    def update_from_expression_editor(params)
      if params[:chosen_typ] && params[:chosen_typ] != exp_typ
        change_exp_typ(params[:chosen_typ])
      else
        case exp_typ

Checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one. Blocks that are calls to builtin iteration methods (e.g. `ary.map{...}) also add one, others are ignored.

def each_child_node(*types)               # count begins: 1
  unless block_given?                     # unless: +1
    return to_enum(__method__, *types)

  children.each do |child|                # each{}: +1
    next unless child.is_a?(Node)         # unless: +1

    yield child if types.empty? ||        # if: +1, ||: +1
                   types.include?(child.type)
  end

  self
end                                       # total: 6

Method update_from_expression_editor has 176 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def update_from_expression_editor(params)
      if params[:chosen_typ] && params[:chosen_typ] != exp_typ
        change_exp_typ(params[:chosen_typ])
      else
        case exp_typ
Severity: Major
Found in app/controllers/application_controller/filter/expression.rb - About 7 hrs to fix

Method update_from_exp_tree has a Cognitive Complexity of 44 (exceeds 5 allowed). Consider refactoring.
Open

    def update_from_exp_tree(exp)
      exp.delete(:token)
      key = exp.keys.first
      if exp[key]['field']
        typ = 'field'
Severity: Minor
Found in app/controllers/application_controller/filter/expression.rb - About 6 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

File expression.rb has 536 lines of code (exceeds 400 allowed). Consider refactoring.
Open

module ApplicationController::Filter
  EXP_TODAY = "Today".freeze
  EXP_FROM = "FROM".freeze
  EXP_IS = "IS".freeze

Severity: Major
Found in app/controllers/application_controller/filter/expression.rb - About 5 hrs to fix

Method process_changed_expression has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring.
Open

    def process_changed_expression(params, chosen_key, exp_key, exp_value, exp_valx)
      # Remove the second exp_value if the operator changed from EXP_FROM
      self[exp_value].delete_at(1) if self[exp_key] == EXP_FROM

      # Set THROUGH value if changing to FROM
Severity: Minor
Found in app/controllers/application_controller/filter/expression.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 prefill_val_types has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
Open

    def prefill_val_types
      self.val1 ||= {}
      self.val2 ||= {}
      val1[:type] = case exp_typ
                    when 'field'
Severity: Minor
Found in app/controllers/application_controller/filter/expression.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

Cyclomatic complexity for update_from_exp_tree is too high. [27/11]
Open

    def update_from_exp_tree(exp)
      exp.delete(:token)
      key = exp.keys.first
      if exp[key]['field']
        typ = 'field'

Checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one. Blocks that are calls to builtin iteration methods (e.g. `ary.map{...}) also add one, others are ignored.

def each_child_node(*types)               # count begins: 1
  unless block_given?                     # unless: +1
    return to_enum(__method__, *types)

  children.each do |child|                # each{}: +1
    next unless child.is_a?(Node)         # unless: +1

    yield child if types.empty? ||        # if: +1, ||: +1
                   types.include?(child.type)
  end

  self
end                                       # total: 6

Method update_from_exp_tree has 80 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def update_from_exp_tree(exp)
      exp.delete(:token)
      key = exp.keys.first
      if exp[key]['field']
        typ = 'field'
Severity: Major
Found in app/controllers/application_controller/filter/expression.rb - About 3 hrs to fix

Method process_datetime_expression_field has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
Open

    def process_datetime_expression_field(value_key, exp_key, exp_value_key)
      if [:date, :datetime].include?(self[value_key][:type]) # Seting value for date/time fields
        self[value_key][:date_format] ||= 'r'
        if self[exp_key] == EXP_FROM
          self[exp_value_key] = self[value_key][:date_format] == 's' ? Array.new(2) : [EXP_TODAY, EXP_TODAY]
Severity: Minor
Found in app/controllers/application_controller/filter/expression.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 build_search has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
Open

    def build_search(name_given_by_user, global_search, userid)
      if selected.nil? ||                                # if no search was loaded
         name_given_by_user != selected[:description] || # or user changed the name of loaded search
         selected[:typ] == 'default'                     # or loaded search is default search, save it as my search
        s = build_new_search(name_given_by_user)
Severity: Minor
Found in app/controllers/application_controller/filter/expression.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

Cyclomatic complexity for prefill_val_types is too high. [17/11]
Open

    def prefill_val_types
      self.val1 ||= {}
      self.val2 ||= {}
      val1[:type] = case exp_typ
                    when 'field'

Checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one. Blocks that are calls to builtin iteration methods (e.g. `ary.map{...}) also add one, others are ignored.

def each_child_node(*types)               # count begins: 1
  unless block_given?                     # unless: +1
    return to_enum(__method__, *types)

  children.each do |child|                # each{}: +1
    next unless child.is_a?(Node)         # unless: +1

    yield child if types.empty? ||        # if: +1, ||: +1
                   types.include?(child.type)
  end

  self
end                                       # total: 6

Method process_datetime_selector has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

    def process_datetime_selector(params, param_key_suffix, exp_key = nil)
      param_date_key  = "miq_date_#{param_key_suffix}".to_sym
      param_time_key  = "miq_time_#{param_key_suffix}".to_sym
      return unless params[param_date_key] || params[param_time_key]

Severity: Minor
Found in app/controllers/application_controller/filter/expression.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

Cyclomatic complexity for process_changed_expression is too high. [12/11]
Open

    def process_changed_expression(params, chosen_key, exp_key, exp_value, exp_valx)
      # Remove the second exp_value if the operator changed from EXP_FROM
      self[exp_value].delete_at(1) if self[exp_key] == EXP_FROM

      # Set THROUGH value if changing to FROM

Checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one. Blocks that are calls to builtin iteration methods (e.g. `ary.map{...}) also add one, others are ignored.

def each_child_node(*types)               # count begins: 1
  unless block_given?                     # unless: +1
    return to_enum(__method__, *types)

  children.each do |child|                # each{}: +1
    next unless child.is_a?(Node)         # unless: +1

    yield child if types.empty? ||        # if: +1, ||: +1
                   types.include?(child.type)
  end

  self
end                                       # total: 6

Method prefill_val_types has 29 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def prefill_val_types
      self.val1 ||= {}
      self.val2 ||= {}
      val1[:type] = case exp_typ
                    when 'field'
Severity: Minor
Found in app/controllers/application_controller/filter/expression.rb - About 1 hr to fix

Method through_choices has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

    def self.through_choices(from_choice)
      return nil if from_choice.nil?

      tc = if ViewHelper::FROM_HOURS.include?(from_choice)
             ViewHelper::FROM_HOURS
Severity: Minor
Found in app/controllers/application_controller/filter/expression.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 val_type_for has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

    def val_type_for(key, field)
      if !self[key] || !self[field]
        nil
      elsif self[key].starts_with?('REG')
        :regexp
Severity: Minor
Found in app/controllers/application_controller/filter/expression.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 exp_available_cfields has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

    def exp_available_cfields
      MiqExpression.miq_adv_search_lists(exp_model, :exp_available_finds).each_with_object([]) do |af, res|
        next if af.last == exp_field
        next unless af.last.split('-').first == exp_field.split('-').first

Severity: Minor
Found in app/controllers/application_controller/filter/expression.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

Avoid deeply nested control flow statements.
Open

              if exp_model != '_display_filter_' &&
                 MiqExpression::Field.parse(exp_field).plural? &&
                 !%i[date datetime].include?(chosen_field_col_type) &&
                 chosen_field_col_type.object_id != :integer.object_id
                self.exp_key = 'CONTAINS' # CONTAINS is valid only for plural tables
Severity: Major
Found in app/controllers/application_controller/filter/expression.rb - About 45 mins to fix

Avoid deeply nested control flow statements.
Open

              self.exp_key = nil unless MiqExpression.get_col_operators(:count).include?(exp_key)
Severity: Major
Found in app/controllers/application_controller/filter/expression.rb - About 45 mins to fix

Avoid deeply nested control flow statements.
Open

              self.exp_skey = nil unless MiqExpression.get_col_operators(exp_field).include?(exp_skey)
Severity: Major
Found in app/controllers/application_controller/filter/expression.rb - About 45 mins to fix

Avoid deeply nested control flow statements.
Open

              self.exp_ckey = nil unless MiqExpression.get_col_operators(exp_cfield).include?(exp_ckey)
Severity: Major
Found in app/controllers/application_controller/filter/expression.rb - About 45 mins to fix

Method process_changed_expression has 5 arguments (exceeds 4 allowed). Consider refactoring.
Open

    def process_changed_expression(params, chosen_key, exp_key, exp_value, exp_valx)
Severity: Minor
Found in app/controllers/application_controller/filter/expression.rb - About 35 mins to fix

Avoid more than 3 levels of block nesting.
Open

            self.exp_value = params[:user_input] == '1' ? :user_input : ''

Checks for excessive nesting of conditional and looping constructs.

You can configure if blocks are considered using the CountBlocks option. When set to false (the default) blocks are not counted towards the nesting level. Set to true to count blocks as well.

The maximum level of nesting allowed is configurable.

Avoid more than 3 levels of block nesting.
Open

            if params[:chosen_field] == '<Choose>'
              self.exp_field = nil
              self.exp_key = nil
            else
              # for date time fields we should show After/Before etc. options

Checks for excessive nesting of conditional and looping constructs.

You can configure if blocks are considered using the CountBlocks option. When set to false (the default) blocks are not counted towards the nesting level. Set to true to count blocks as well.

The maximum level of nesting allowed is configurable.

Avoid more than 3 levels of block nesting.
Open

            if params[:chosen_count] == '<Choose>'
              self.exp_count = nil
              self.exp_key = nil
              self.exp_value = nil
            else

Checks for excessive nesting of conditional and looping constructs.

You can configure if blocks are considered using the CountBlocks option. When set to false (the default) blocks are not counted towards the nesting level. Set to true to count blocks as well.

The maximum level of nesting allowed is configurable.

Avoid more than 3 levels of block nesting.
Open

            self.exp_value = params[:user_input] == '1' ? :user_input : nil

Checks for excessive nesting of conditional and looping constructs.

You can configure if blocks are considered using the CountBlocks option. When set to false (the default) blocks are not counted towards the nesting level. Set to true to count blocks as well.

The maximum level of nesting allowed is configurable.

Avoid more than 3 levels of block nesting.
Open

            self.exp_ckey = exp_check == 'checkcount' ? '=' : nil

Checks for excessive nesting of conditional and looping constructs.

You can configure if blocks are considered using the CountBlocks option. When set to false (the default) blocks are not counted towards the nesting level. Set to true to count blocks as well.

The maximum level of nesting allowed is configurable.

Avoid more than 3 levels of block nesting.
Open

            if params[:chosen_field] == '<Choose>'
              self.exp_field = nil
              self.exp_skey = nil
            else
              self.exp_skey = nil unless MiqExpression.get_col_operators(exp_field).include?(exp_skey)

Checks for excessive nesting of conditional and looping constructs.

You can configure if blocks are considered using the CountBlocks option. When set to false (the default) blocks are not counted towards the nesting level. Set to true to count blocks as well.

The maximum level of nesting allowed is configurable.

Avoid more than 3 levels of block nesting.
Open

                                       v + ' 00:00' unless v.include?(':')

Checks for excessive nesting of conditional and looping constructs.

You can configure if blocks are considered using the CountBlocks option. When set to false (the default) blocks are not counted towards the nesting level. Set to true to count blocks as well.

The maximum level of nesting allowed is configurable.

Avoid more than 3 levels of block nesting.
Open

                                       v.split(' ').first if v.include?(':')

Checks for excessive nesting of conditional and looping constructs.

You can configure if blocks are considered using the CountBlocks option. When set to false (the default) blocks are not counted towards the nesting level. Set to true to count blocks as well.

The maximum level of nesting allowed is configurable.

Avoid more than 3 levels of block nesting.
Open

            if params[:chosen_cfield] == '<Choose>'
              self.exp_cfield = nil
              self.exp_ckey = nil
            else
              self.exp_ckey = nil unless MiqExpression.get_col_operators(exp_cfield).include?(exp_ckey)

Checks for excessive nesting of conditional and looping constructs.

You can configure if blocks are considered using the CountBlocks option. When set to false (the default) blocks are not counted towards the nesting level. Set to true to count blocks as well.

The maximum level of nesting allowed is configurable.

Avoid more than 3 levels of block nesting.
Open

                         case exp_typ
                         when 'field', 'find'
                           MiqExpression.value2human(exp_field).split(':').last
                         when 'tag'
                           MiqExpression.value2human(exp_tag).split(':').last

Checks for excessive nesting of conditional and looping constructs.

You can configure if blocks are considered using the CountBlocks option. When set to false (the default) blocks are not counted towards the nesting level. Set to true to count blocks as well.

The maximum level of nesting allowed is configurable.

Avoid more than 3 levels of block nesting.
Open

            self.exp_value = params[:user_input] == '1' ? :user_input : nil

Checks for excessive nesting of conditional and looping constructs.

You can configure if blocks are considered using the CountBlocks option. When set to false (the default) blocks are not counted towards the nesting level. Set to true to count blocks as well.

The maximum level of nesting allowed is configurable.

Avoid more than 3 levels of block nesting.
Open

            self.exp_tag = params[:chosen_tag] == '<Choose>' ? nil : params[:chosen_tag]

Checks for excessive nesting of conditional and looping constructs.

You can configure if blocks are considered using the CountBlocks option. When set to false (the default) blocks are not counted towards the nesting level. Set to true to count blocks as well.

The maximum level of nesting allowed is configurable.

Avoid more than 3 levels of block nesting.
Open

            self.exp_key = exp_model == '_display_filter_' ? '=' : 'CONTAINS'

Checks for excessive nesting of conditional and looping constructs.

You can configure if blocks are considered using the CountBlocks option. When set to false (the default) blocks are not counted towards the nesting level. Set to true to count blocks as well.

The maximum level of nesting allowed is configurable.

Avoid more than 3 levels of block nesting.
Open

            if (exp_cfield.present? && exp_field.present?) && # Clear expression check portion
               (exp_cfield == exp_field || # if find field matches check field
                exp_cfield.split('-').first != exp_field.split('-').first) # or user chose a different table field
              self.exp_check = 'checkall'
              self.exp_cfield = nil

Checks for excessive nesting of conditional and looping constructs.

You can configure if blocks are considered using the CountBlocks option. When set to false (the default) blocks are not counted towards the nesting level. Set to true to count blocks as well.

The maximum level of nesting allowed is configurable.

Avoid more than 3 levels of block nesting.
Open

            unless val2[:through_choices].include?(exp_cvalue[1])
              exp_cvalue[1] = val2[:through_choices].first
            end

Checks for excessive nesting of conditional and looping constructs.

You can configure if blocks are considered using the CountBlocks option. When set to false (the default) blocks are not counted towards the nesting level. Set to true to count blocks as well.

The maximum level of nesting allowed is configurable.

Avoid more than 3 levels of block nesting.
Open

            unless val1[:through_choices].include?(exp_value[1])
              exp_value[1] = val1[:through_choices].first
            end

Checks for excessive nesting of conditional and looping constructs.

You can configure if blocks are considered using the CountBlocks option. When set to false (the default) blocks are not counted towards the nesting level. Set to true to count blocks as well.

The maximum level of nesting allowed is configurable.

Avoid immutable Array literals in loops. It is better to extract it into a local variable or a constant.
Open

      [val1, val2].compact.any? { |val| [:date, :datetime].include?(val[:type]) }

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

      if params[:date_format_1] && exp_value.present?
        val1[:date_format] = params[:date_format_1]
        exp_value.collect! { |_| params[:date_format_1] == 's' ? nil : EXP_TODAY }
        val1[:through_choices] = Expression.through_choices(exp_value[0]) if params[:date_format_1] == 'r'
      end
Severity: Minor
Found in app/controllers/application_controller/filter/expression.rb and 1 other location - About 35 mins to fix
app/controllers/application_controller/filter/expression.rb on lines 366..370

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

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

      if params[:date_format_2] && exp_cvalue.present?
        val2[:date_format] = params[:date_format_2]
        exp_cvalue.collect! { |_| params[:date_format_2] == 's' ? nil : EXP_TODAY }
        val2[:through_choices] = Expression.through_choices(exp_cvalue[0]) if params[:date_format_2] == 'r'
      end
Severity: Minor
Found in app/controllers/application_controller/filter/expression.rb and 1 other location - About 35 mins to fix
app/controllers/application_controller/filter/expression.rb on lines 361..365

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

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

      if val2 && val2[:type] == :bytes
        if is_numeric?(exp_cvalue)                            # Value is a number
          self.val2_suffix = :bytes                           #  Default to :bytes
          self.exp_cvalue = exp_cvalue.to_s                   #  Get the value
        else                                                  # Value is a string
Severity: Minor
Found in app/controllers/application_controller/filter/expression.rb and 1 other location - About 25 mins to fix
app/controllers/application_controller/filter/expression.rb on lines 427..435

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

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

        if val1 && val1[:type] == :bytes
          if is_numeric?(exp_value)                           # Value is a number
            self.val1_suffix = :bytes                         #  Default to :bytes
            self.exp_value = exp_value.to_s                   #  Get the value
          else                                                # Value is a string
Severity: Minor
Found in app/controllers/application_controller/filter/expression.rb and 1 other location - About 25 mins to fix
app/controllers/application_controller/filter/expression.rb on lines 437..445

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

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

            if params[:chosen_field] == '<Choose>'
              self.exp_field = nil
              self.exp_skey = nil
            else
              self.exp_skey = nil unless MiqExpression.get_col_operators(exp_field).include?(exp_skey)
Severity: Minor
Found in app/controllers/application_controller/filter/expression.rb and 1 other location - About 25 mins to fix
app/controllers/application_controller/filter/expression.rb on lines 283..290

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

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

            if params[:chosen_cfield] == '<Choose>'
              self.exp_cfield = nil
              self.exp_ckey = nil
            else
              self.exp_ckey = nil unless MiqExpression.get_col_operators(exp_cfield).include?(exp_ckey)
Severity: Minor
Found in app/controllers/application_controller/filter/expression.rb and 1 other location - About 25 mins to fix
app/controllers/application_controller/filter/expression.rb on lines 248..255

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

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