lib/tagging_controller.rb

Summary

Maintainability
A
3 hrs
Test Coverage

Assignment Branch Condition size for add_tags is too high. [74.44/15]
Open

    def add_tags
      zoom_class = zoom_class_from_controller(params[:controller])
      item_key = zoom_class.underscore.to_sym

      @item = item_from_controller_and_id
Severity: Minor
Found in lib/tagging_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. [44/10]
Open

    def add_tags
      zoom_class = zoom_class_from_controller(params[:controller])
      item_key = zoom_class.underscore.to_sym

      @item = item_from_controller_and_id
Severity: Minor
Found in lib/tagging_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 has too many lines. [22/10]
Open

    def self.included(klass)
      controller = klass.name.gsub('Controller', '')
      auto_complete_methods = []
      # If we're in the Baskets controller, we have to make all zoom class tag completion methods on load
      if controller == 'Baskets'
Severity: Minor
Found in lib/tagging_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 included is too high. [21.75/15]
Open

    def self.included(klass)
      controller = klass.name.gsub('Controller', '')
      auto_complete_methods = []
      # If we're in the Baskets controller, we have to make all zoom class tag completion methods on load
      if controller == 'Baskets'
Severity: Minor
Found in lib/tagging_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 add_tags has 44 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def add_tags
      zoom_class = zoom_class_from_controller(params[:controller])
      item_key = zoom_class.underscore.to_sym

      @item = item_from_controller_and_id
Severity: Minor
Found in lib/tagging_controller.rb - About 1 hr to fix

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

        def add_tags
          zoom_class = zoom_class_from_controller(params[:controller])
          item_key = zoom_class.underscore.to_sym
    
          @item = item_from_controller_and_id
    Severity: Minor
    Found in lib/tagging_controller.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 included has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def self.included(klass)
          controller = klass.name.gsub('Controller', '')
          auto_complete_methods = []
          # If we're in the Baskets controller, we have to make all zoom class tag completion methods on load
          if controller == 'Baskets'
    Severity: Minor
    Found in lib/tagging_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

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

            respond_to do |format|
              flash[:error] = I18n.t('tagging_controller_lib.add_tags.no_tags_entered', item_title: @item.title)
              format.html { redirect_to_show_for @item, private: (params[:private] == 'true') }
    Severity: Minor
    Found in lib/tagging_controller.rb and 1 other location - About 15 mins to fix
    lib/tagging_controller.rb on lines 61..63

    Duplicated Code

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

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

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

    Tuning

    This issue has a mass of 26.

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

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

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

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

    Refactorings

    Further Reading

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

              respond_to do |format|
                flash[:notice] = I18n.t('tagging_controller_lib.add_tags.tags_added', item_title: @item.title)
                format.html { redirect_to_show_for @item, private: (params[:private] == 'true') }
    Severity: Minor
    Found in lib/tagging_controller.rb and 1 other location - About 15 mins to fix
    lib/tagging_controller.rb on lines 79..81

    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

    Prefer single-quoted strings inside interpolations.
    Open

            params[item_key][:tag_list] = "#{@item.tag_list.join(", ")}, #{params[item_key][:tag_list]}"
    Severity: Minor
    Found in lib/tagging_controller.rb by rubocop

    This cop checks that quotes inside the string interpolation match the configured preference.

    Example: EnforcedStyle: single_quotes (default)

    # bad
    result = "Tests #{success ? "PASS" : "FAIL"}"
    
    # good
    result = "Tests #{success ? 'PASS' : 'FAIL'}"

    Example: EnforcedStyle: double_quotes

    # bad
    result = "Tests #{success ? 'PASS' : 'FAIL'}"
    
    # good
    result = "Tests #{success ? "PASS" : "FAIL"}"

    Use the return of the conditional for variable assignment and comparison.
    Open

            case controller
            when 'Images'
              zoom_class = 'StillImage'
            when 'Audio'
              zoom_class = 'AudioRecording'
    Severity: Minor
    Found in lib/tagging_controller.rb by rubocop

    Put empty method definitions on a single line.
    Open

        def after_tags_added(options)
        end
    Severity: Minor
    Found in lib/tagging_controller.rb by rubocop

    This cop checks for the formatting of empty method definitions. By default it enforces empty method definitions to go on a single line (compact style), but it can be configured to enforce the end to go on its own line (expanded style).

    Note: A method definition is not considered empty if it contains comments.

    Example: EnforcedStyle: compact (default)

    # bad
    def foo(bar)
    end
    
    def self.foo(bar)
    end
    
    # good
    def foo(bar); end
    
    def foo(bar)
      # baz
    end
    
    def self.foo(bar); end

    Example: EnforcedStyle: expanded

    # bad
    def foo(bar); end
    
    def self.foo(bar); end
    
    # good
    def foo(bar)
    end
    
    def self.foo(bar)
    end

    Redundant curly braces around a hash parameter.
    Open

              klass.send :auto_complete_for, item_key, :tag_list, {}, { through: { object: 'tag', method: 'name' } }
    Severity: Minor
    Found in lib/tagging_controller.rb by rubocop

    This cop checks for braces around the last parameter in a method call if the last parameter is a hash. It supports braces, no_braces and context_dependent styles.

    Example: EnforcedStyle: braces

    # The `braces` style enforces braces around all method
    # parameters that are hashes.
    
    # bad
    some_method(x, y, a: 1, b: 2)
    
    # good
    some_method(x, y, {a: 1, b: 2})

    Example: EnforcedStyle: no_braces (default)

    # The `no_braces` style checks that the last parameter doesn't
    # have braces around it.
    
    # bad
    some_method(x, y, {a: 1, b: 2})
    
    # good
    some_method(x, y, a: 1, b: 2)

    Example: EnforcedStyle: context_dependent

    # The `context_dependent` style checks that the last parameter
    # doesn't have braces around it, but requires braces if the
    # second to last parameter is also a hash literal.
    
    # bad
    some_method(x, y, {a: 1, b: 2})
    some_method(x, y, {a: 1, b: 2}, a: 1, b: 2)
    
    # good
    some_method(x, y, a: 1, b: 2)
    some_method(x, y, {a: 1, b: 2}, {a: 1, b: 2})

    There are no issues that match your filters.

    Category
    Status