lib/extended_content_controller.rb

Summary

Maintainability
C
7 hrs
Test Coverage

Assignment Branch Condition size for included is too high. [72.59/15]
Open

    def self.included(klass)
      # stuff related to flagging and moderation
      klass.send :include, FlaggingController

      # Kieran Pilkington, 2008/10/23
Severity: Minor
Found in lib/extended_content_controller.rb by rubocop

This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

Method has too many lines. [61/10]
Open

    def self.included(klass)
      # stuff related to flagging and moderation
      klass.send :include, FlaggingController

      # Kieran Pilkington, 2008/10/23
Severity: Minor
Found in lib/extended_content_controller.rb by rubocop

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Assignment Branch Condition size for build_relations_from_topic_type_extended_field_choices is too high. [29.29/15]
Open

      def build_relations_from_topic_type_extended_field_choices(extended_values = nil)
        params_key = zoom_class_params_key_from_controller(params[:controller])
        extended_values ||= params[params_key][:extended_content_values] if !params[params_key].blank? && !params[params_key][:extended_content_values].blank?

        # no extended_values, nothing to do
Severity: Minor
Found in lib/extended_content_controller.rb by rubocop

This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

Perceived complexity for included is too high. [19/7]
Open

    def self.included(klass)
      # stuff related to flagging and moderation
      klass.send :include, FlaggingController

      # Kieran Pilkington, 2008/10/23
Severity: Minor
Found in lib/extended_content_controller.rb by rubocop

This cop tries to produce a complexity score that's a measure of the complexity the reader experiences when looking at a method. For that reason it considers when nodes as something that doesn't add as much complexity as an if or a &&. Except if it's one of those special case/when constructs where there's no expression after case. Then the cop treats it as an if/elsif/elsif... and lets all the when nodes count. In contrast to the CyclomaticComplexity cop, this cop considers else nodes as adding complexity.

Example:

def my_method                   # 1
  if cond                       # 1
    case var                    # 2 (0.8 + 4 * 0.2, rounded)
    when 1 then func_one
    when 2 then func_two
    when 3 then func_three
    when 4..10 then func_other
    end
  else                          # 1
    do_something until a && b   # 2
  end                           # ===
end                             # 7 complexity points

Cyclomatic complexity for included is too high. [16/6]
Open

    def self.included(klass)
      # stuff related to flagging and moderation
      klass.send :include, FlaggingController

      # Kieran Pilkington, 2008/10/23
Severity: Minor
Found in lib/extended_content_controller.rb by rubocop

This cop 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.

Method has too many lines. [19/10]
Open

      def build_relations_from_topic_type_extended_field_choices(extended_values = nil)
        params_key = zoom_class_params_key_from_controller(params[:controller])
        extended_values ||= params[params_key][:extended_content_values] if !params[params_key].blank? && !params[params_key][:extended_content_values].blank?

        # no extended_values, nothing to do
Severity: Minor
Found in lib/extended_content_controller.rb by rubocop

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Assignment Branch Condition size for skip_or_add_relation_for is too high. [23.75/15]
Open

      def skip_or_add_relation_for(key, value)
        # Check before any further queries are made that the field looks like a topic type string
        return unless value.present? && value =~ /^.+ \(\w+:\/\/(.+)\)$/ && $1

        # Check if this extended content belongs to an extended field that is a topic type field type
Severity: Minor
Found in lib/extended_content_controller.rb by rubocop

This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

Method included has 61 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def self.included(klass)
      # stuff related to flagging and moderation
      klass.send :include, FlaggingController

      # Kieran Pilkington, 2008/10/23
Severity: Major
Found in lib/extended_content_controller.rb - About 2 hrs to fix

    Method build_relations_from_topic_type_extended_field_choices has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open

          def build_relations_from_topic_type_extended_field_choices(extended_values = nil)
            params_key = zoom_class_params_key_from_controller(params[:controller])
            extended_values ||= params[params_key][:extended_content_values] if !params[params_key].blank? && !params[params_key][:extended_content_values].blank?
    
            # no extended_values, nothing to do
    Severity: Minor
    Found in lib/extended_content_controller.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 has too many lines. [15/10]
    Open

          def skip_or_add_relation_for(key, value)
            # Check before any further queries are made that the field looks like a topic type string
            return unless value.present? && value =~ /^.+ \(\w+:\/\/(.+)\)$/ && $1
    
            # Check if this extended content belongs to an extended field that is a topic type field type
    Severity: Minor
    Found in lib/extended_content_controller.rb by rubocop

    This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

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

          def skip_or_add_relation_for(key, value)
            # Check before any further queries are made that the field looks like a topic type string
            return unless value.present? && value =~ /^.+ \(\w+:\/\/(.+)\)$/ && $1
    
            # Check if this extended content belongs to an extended field that is a topic type field type
    Severity: Minor
    Found in lib/extended_content_controller.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 skip_or_add_relation_for is too high. [9/6]
    Open

          def skip_or_add_relation_for(key, value)
            # Check before any further queries are made that the field looks like a topic type string
            return unless value.present? && value =~ /^.+ \(\w+:\/\/(.+)\)$/ && $1
    
            # Check if this extended content belongs to an extended field that is a topic type field type
    Severity: Minor
    Found in lib/extended_content_controller.rb by rubocop

    This cop 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.

    Perceived complexity for skip_or_add_relation_for is too high. [9/7]
    Open

          def skip_or_add_relation_for(key, value)
            # Check before any further queries are made that the field looks like a topic type string
            return unless value.present? && value =~ /^.+ \(\w+:\/\/(.+)\)$/ && $1
    
            # Check if this extended content belongs to an extended field that is a topic type field type
    Severity: Minor
    Found in lib/extended_content_controller.rb by rubocop

    This cop tries to produce a complexity score that's a measure of the complexity the reader experiences when looking at a method. For that reason it considers when nodes as something that doesn't add as much complexity as an if or a &&. Except if it's one of those special case/when constructs where there's no expression after case. Then the cop treats it as an if/elsif/elsif... and lets all the when nodes count. In contrast to the CyclomaticComplexity cop, this cop considers else nodes as adding complexity.

    Example:

    def my_method                   # 1
      if cond                       # 1
        case var                    # 2 (0.8 + 4 * 0.2, rounded)
        when 1 then func_one
        when 2 then func_two
        when 3 then func_three
        when 4..10 then func_other
        end
      else                          # 1
        do_something until a && b   # 2
      end                           # ===
    end                             # 7 complexity points

    Perceived complexity for build_relations_from_topic_type_extended_field_choices is too high. [8/7]
    Open

          def build_relations_from_topic_type_extended_field_choices(extended_values = nil)
            params_key = zoom_class_params_key_from_controller(params[:controller])
            extended_values ||= params[params_key][:extended_content_values] if !params[params_key].blank? && !params[params_key][:extended_content_values].blank?
    
            # no extended_values, nothing to do
    Severity: Minor
    Found in lib/extended_content_controller.rb by rubocop

    This cop tries to produce a complexity score that's a measure of the complexity the reader experiences when looking at a method. For that reason it considers when nodes as something that doesn't add as much complexity as an if or a &&. Except if it's one of those special case/when constructs where there's no expression after case. Then the cop treats it as an if/elsif/elsif... and lets all the when nodes count. In contrast to the CyclomaticComplexity cop, this cop considers else nodes as adding complexity.

    Example:

    def my_method                   # 1
      if cond                       # 1
        case var                    # 2 (0.8 + 4 * 0.2, rounded)
        when 1 then func_one
        when 2 then func_two
        when 3 then func_three
        when 4..10 then func_other
        end
      else                          # 1
        do_something until a && b   # 2
      end                           # ===
    end                             # 7 complexity points

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

        def self.included(klass)
          # stuff related to flagging and moderation
          klass.send :include, FlaggingController
    
          # Kieran Pilkington, 2008/10/23
    Severity: Minor
    Found in lib/extended_content_controller.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

    Avoid more than 3 levels of block nesting.
    Open

                unless relation_already_exists
                  logger.debug("Add relation for #{value}, with id of #{topic.id}")
                  ContentItemRelation.new_relation_to_topic(topic, current_item)
                  # use async backgroundrb worker rather than slowing down response to request to wait for related topic rebuild
                  # topic.prepare_and_save_to_zoom
    Severity: Minor
    Found in lib/extended_content_controller.rb by rubocop

    This cop 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.

    Use each_value instead of values.each.
    Open

                  value.values.each do |value|
    Severity: Minor
    Found in lib/extended_content_controller.rb by rubocop

    This cop checks for uses of each_key and each_value Hash methods.

    Note: If you have an array of two-element arrays, you can put parentheses around the block arguments to indicate that you're not working with a hash, and suppress RuboCop offenses.

    Example:

    # bad
    hash.keys.each { |k| p k }
    hash.values.each { |v| p v }
    hash.each { |k, _v| p k }
    hash.each { |_k, v| p v }
    
    # good
    hash.each_key { |k| p k }
    hash.each_value { |v| p v }

    TODO found
    Open

            # TODO: limit this to content_type or topic type
    Severity: Minor
    Found in lib/extended_content_controller.rb by fixme

    Avoid the use of Perl-style backrefs.
    Open

            return unless value.present? && value =~ /^.+ \(\w+:\/\/(.+)\)$/ && $1
    Severity: Minor
    Found in lib/extended_content_controller.rb by rubocop

    This cop looks for uses of Perl-style regexp match backreferences like $1, $2, etc.

    Example:

    # bad
    puts $1
    
    # good
    puts Regexp.last_match(1)

    Method definitions must not be nested. Use lambda instead.
    Open

          def load_content_type
            @content_type = ContentType.find_by_class_name(zoom_class_from_controller(params[:controller]))
          end
    Severity: Minor
    Found in lib/extended_content_controller.rb by rubocop

    This cop checks for nested method definitions.

    Example:

    # bad
    
    # `bar` definition actually produces methods in the same scope
    # as the outer `foo` method. Furthermore, the `bar` method
    # will be redefined every time `foo` is invoked.
    def foo
      def bar
      end
    end

    Example:

    # good
    
    def foo
      bar = -> { puts 'hello' }
      bar.call
    end

    Example:

    # good
    
    def foo
      self.class_eval do
        def bar
        end
      end
    end
    
    def foo
      self.module_exec do
        def bar
        end
      end
    end

    Example:

    # good
    
    def foo
      class << self
        def bar
        end
      end
    end

    Shadowing outer local variable - value.
    Open

                  value.values.each do |value|
    Severity: Minor
    Found in lib/extended_content_controller.rb by rubocop

    This cop looks for use of the same name as outer local variables for block arguments or block local variables. This is a mimic of the warning "shadowing outer local variable - foo" from ruby -cw.

    Example:

    # bad
    
    def some_method
      foo = 1
    
      2.times do |foo| # shadowing outer `foo`
        do_something(foo)
      end
    end

    Example:

    # good
    
    def some_method
      foo = 1
    
      2.times do |bar|
        do_something(bar)
      end
    end

    Use topic_id.positive? instead of topic_id > 0.
    Open

            if topic_id && topic_id > 0
    Severity: Minor
    Found in lib/extended_content_controller.rb by rubocop

    This cop checks for usage of comparison operators (==, >, <) to test numbers as zero, positive, or negative. These can be replaced by their respective predicate methods. The cop can also be configured to do the reverse.

    The cop disregards #nonzero? as it its value is truthy or falsey, but not true and false, and thus not always interchangeable with != 0.

    The cop ignores comparisons to global variables, since they are often populated with objects which can be compared with integers, but are not themselves Interger polymorphic.

    Example: EnforcedStyle: predicate (default)

    # bad
    
    foo == 0
    0 > foo
    bar.baz > 0
    
    # good
    
    foo.zero?
    foo.negative?
    bar.baz.positive?

    Example: EnforcedStyle: comparison

    # bad
    
    foo.zero?
    foo.negative?
    bar.baz.positive?
    
    # good
    
    foo == 0
    0 > foo
    bar.baz > 0

    Method definitions must not be nested. Use lambda instead.
    Open

          def skip_or_add_relation_for(key, value)
            # Check before any further queries are made that the field looks like a topic type string
            return unless value.present? && value =~ /^.+ \(\w+:\/\/(.+)\)$/ && $1
    
            # Check if this extended content belongs to an extended field that is a topic type field type
    Severity: Minor
    Found in lib/extended_content_controller.rb by rubocop

    This cop checks for nested method definitions.

    Example:

    # bad
    
    # `bar` definition actually produces methods in the same scope
    # as the outer `foo` method. Furthermore, the `bar` method
    # will be redefined every time `foo` is invoked.
    def foo
      def bar
      end
    end

    Example:

    # good
    
    def foo
      bar = -> { puts 'hello' }
      bar.call
    end

    Example:

    # good
    
    def foo
      self.class_eval do
        def bar
        end
      end
    end
    
    def foo
      self.module_exec do
        def bar
        end
      end
    end

    Example:

    # good
    
    def foo
      class << self
        def bar
        end
      end
    end

    Avoid the use of Perl-style backrefs.
    Open

            topic_id = $1.dup.split('/').last.to_i
    Severity: Minor
    Found in lib/extended_content_controller.rb by rubocop

    This cop looks for uses of Perl-style regexp match backreferences like $1, $2, etc.

    Example:

    # bad
    puts $1
    
    # good
    puts Regexp.last_match(1)

    Use %r around regular expression.
    Open

            return unless value.present? && value =~ /^.+ \(\w+:\/\/(.+)\)$/ && $1
    Severity: Minor
    Found in lib/extended_content_controller.rb by rubocop

    This cop enforces using // or %r around regular expressions.

    Example: EnforcedStyle: slashes (default)

    # bad
    snake_case = %r{^[\dA-Z_]+$}
    
    # bad
    regex = %r{
      foo
      (bar)
      (baz)
    }x
    
    # good
    snake_case = /^[\dA-Z_]+$/
    
    # good
    regex = /
      foo
      (bar)
      (baz)
    /x

    Example: EnforcedStyle: percent_r

    # bad
    snake_case = /^[\dA-Z_]+$/
    
    # bad
    regex = /
      foo
      (bar)
      (baz)
    /x
    
    # good
    snake_case = %r{^[\dA-Z_]+$}
    
    # good
    regex = %r{
      foo
      (bar)
      (baz)
    }x

    Example: EnforcedStyle: mixed

    # bad
    snake_case = %r{^[\dA-Z_]+$}
    
    # bad
    regex = /
      foo
      (bar)
      (baz)
    /x
    
    # good
    snake_case = /^[\dA-Z_]+$/
    
    # good
    regex = %r{
      foo
      (bar)
      (baz)
    }x

    Example: AllowInnerSlashes: false (default)

    # If `false`, the cop will always recommend using `%r` if one or more
    # slashes are found in the regexp string.
    
    # bad
    x =~ /home\//
    
    # good
    x =~ %r{home/}

    Example: AllowInnerSlashes: true

    # good
    x =~ /home\//

    Method definitions must not be nested. Use lambda instead.
    Open

          def qualified_name_for_field(extended_field)
            extended_field.label.downcase.gsub(/\s/, '_')
          end
    Severity: Minor
    Found in lib/extended_content_controller.rb by rubocop

    This cop checks for nested method definitions.

    Example:

    # bad
    
    # `bar` definition actually produces methods in the same scope
    # as the outer `foo` method. Furthermore, the `bar` method
    # will be redefined every time `foo` is invoked.
    def foo
      def bar
      end
    end

    Example:

    # good
    
    def foo
      bar = -> { puts 'hello' }
      bar.call
    end

    Example:

    # good
    
    def foo
      self.class_eval do
        def bar
        end
      end
    end
    
    def foo
      self.module_exec do
        def bar
        end
      end
    end

    Example:

    # good
    
    def foo
      class << self
        def bar
        end
      end
    end

    Method definitions must not be nested. Use lambda instead.
    Open

          def build_relations_from_topic_type_extended_field_choices(extended_values = nil)
            params_key = zoom_class_params_key_from_controller(params[:controller])
            extended_values ||= params[params_key][:extended_content_values] if !params[params_key].blank? && !params[params_key][:extended_content_values].blank?
    
            # no extended_values, nothing to do
    Severity: Minor
    Found in lib/extended_content_controller.rb by rubocop

    This cop checks for nested method definitions.

    Example:

    # bad
    
    # `bar` definition actually produces methods in the same scope
    # as the outer `foo` method. Furthermore, the `bar` method
    # will be redefined every time `foo` is invoked.
    def foo
      def bar
      end
    end

    Example:

    # good
    
    def foo
      bar = -> { puts 'hello' }
      bar.call
    end

    Example:

    # good
    
    def foo
      self.class_eval do
        def bar
        end
      end
    end
    
    def foo
      self.module_exec do
        def bar
        end
      end
    end

    Example:

    # good
    
    def foo
      class << self
        def bar
        end
      end
    end

    Use a guard clause instead of wrapping the code inside a conditional expression.
    Open

            if topic_id && topic_id > 0
    Severity: Minor
    Found in lib/extended_content_controller.rb by rubocop

    Use a guard clause instead of wrapping the code inside a conditional expression

    Example:

    # bad
    def test
      if something
        work
      end
    end
    
    # good
    def test
      return unless something
      work
    end
    
    # also good
    def test
      work if something
    end
    
    # bad
    if something
      raise 'exception'
    else
      ok
    end
    
    # good
    raise 'exception' if something
    ok

    There are no issues that match your filters.

    Category
    Status