lib/flagging_controller.rb

Summary

Maintainability
C
1 day
Test Coverage

Module has too many lines. [204/100]
Open

module FlaggingController
  unless included_modules.include? FlaggingController
    # set up our helper methods
    def self.included(klass)
      klass.helper_method :can_preview?
Severity: Minor
Found in lib/flagging_controller.rb by rubocop

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

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

    def restore
      setup_flagging_vars

      current_version = @item.version

Severity: Minor
Found in lib/flagging_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 restore is too high. [57.8/15]
Open

    def restore
      setup_flagging_vars

      current_version = @item.version

Severity: Minor
Found in lib/flagging_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

Assignment Branch Condition size for preview is too high. [36.63/15]
Open

    def preview
      setup_flagging_vars

      # no need to preview live version
      if @item.version.to_s == @version
Severity: Minor
Found in lib/flagging_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

Assignment Branch Condition size for setup_flagging_vars is too high. [33.36/15]
Open

    def setup_flagging_vars
      @item = item_from_controller_and_id
      @flag = !params[:flag].blank? ? params[:flag] : nil
      @version = !params[:version].blank? ? params[:version] : @item.version
      @version_after_update = @item.max_version + 1
Severity: Minor
Found in lib/flagging_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

Assignment Branch Condition size for history is too high. [32.94/15]
Open

    def history
      @item = item_from_controller_and_id

      # Only show private versions to authorized people.
      if permitted_to_view_private_items?
Severity: Minor
Found in lib/flagging_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. [26/10]
Open

    def preview
      setup_flagging_vars

      # no need to preview live version
      if @item.version.to_s == @version
Severity: Minor
Found in lib/flagging_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. [25/10]
Open

    def history
      @item = item_from_controller_and_id

      # Only show private versions to authorized people.
      if permitted_to_view_private_items?
Severity: Minor
Found in lib/flagging_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 restore has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
Open

    def restore
      setup_flagging_vars

      current_version = @item.version

Severity: Minor
Found in lib/flagging_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 preview has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
Open

    def preview
      setup_flagging_vars

      # no need to preview live version
      if @item.version.to_s == @version
Severity: Minor
Found in lib/flagging_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. [16/10]
Open

    def flag_version
      setup_flagging_vars

      # Revert to the passed in version if applicable
      @item.revert_to(params[:version]) if !params[:version].blank?
Severity: Minor
Found in lib/flagging_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. [16/10]
Open

    def review
      setup_flagging_vars

      @item.review_this(
        @version, message: @message,
Severity: Minor
Found in lib/flagging_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. [16/10]
Open

    def reject
      setup_flagging_vars

      @item.reject_this(
        @version, message: @message,
Severity: Minor
Found in lib/flagging_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 restore has 54 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def restore
      setup_flagging_vars

      current_version = @item.version

Severity: Major
Found in lib/flagging_controller.rb - About 2 hrs to fix

    Cyclomatic complexity for preview is too high. [10/6]
    Open

        def preview
          setup_flagging_vars
    
          # no need to preview live version
          if @item.version.to_s == @version
    Severity: Minor
    Found in lib/flagging_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 preview is too high. [11/7]
    Open

        def preview
          setup_flagging_vars
    
          # no need to preview live version
          if @item.version.to_s == @version
    Severity: Minor
    Found in lib/flagging_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

    Assignment Branch Condition size for flag_version is too high. [19.34/15]
    Open

        def flag_version
          setup_flagging_vars
    
          # Revert to the passed in version if applicable
          @item.revert_to(params[:version]) if !params[:version].blank?
    Severity: Minor
    Found in lib/flagging_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 restore is too high. [9/7]
    Open

        def restore
          setup_flagging_vars
    
          current_version = @item.version
    
    
    Severity: Minor
    Found in lib/flagging_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 has too many lines. [11/10]
    Open

        def flag_form
          @flag = params[:flag]
          @form_target =
            case @flag
            when SystemSetting.rejected_flag
    Severity: Minor
    Found in lib/flagging_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.

    Cyclomatic complexity for restore is too high. [7/6]
    Open

        def restore
          setup_flagging_vars
    
          current_version = @item.version
    
    
    Severity: Minor
    Found in lib/flagging_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. [11/10]
    Open

        def setup_flagging_vars
          @item = item_from_controller_and_id
          @flag = !params[:flag].blank? ? params[:flag] : nil
          @version = !params[:version].blank? ? params[:version] : @item.version
          @version_after_update = @item.max_version + 1
    Severity: Minor
    Found in lib/flagging_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 setup_flagging_vars has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

        def setup_flagging_vars
          @item = item_from_controller_and_id
          @flag = !params[:flag].blank? ? params[:flag] : nil
          @version = !params[:version].blank? ? params[:version] : @item.version
          @version_after_update = @item.max_version + 1
    Severity: Minor
    Found in lib/flagging_controller.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 history has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

        def history
          @item = item_from_controller_and_id
    
          # Only show private versions to authorized people.
          if permitted_to_view_private_items?
    Severity: Minor
    Found in lib/flagging_controller.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 preview has 26 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def preview
          setup_flagging_vars
    
          # no need to preview live version
          if @item.version.to_s == @version
    Severity: Minor
    Found in lib/flagging_controller.rb - About 1 hr to fix

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

          def review
            setup_flagging_vars
      
            @item.review_this(
              @version, message: @message,
      Severity: Minor
      Found in lib/flagging_controller.rb and 1 other location - About 35 mins to fix
      lib/flagging_controller.rb on lines 190..211

      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

          def reject
            setup_flagging_vars
      
            @item.reject_this(
              @version, message: @message,
      Severity: Minor
      Found in lib/flagging_controller.rb and 1 other location - About 35 mins to fix
      lib/flagging_controller.rb on lines 166..187

      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

      Useless assignment to variable - flagged_version.
      Open

            flagged_version = @item.flag_live_version_with(@flag, @message)
      Severity: Minor
      Found in lib/flagging_controller.rb by rubocop

      This cop checks for every useless assignment to local variable in every scope. The basic idea for this cop was from the warning of ruby -cw:

      assigned but unused variable - foo

      Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.

      Example:

      # bad
      
      def some_method
        some_var = 1
        do_something
      end

      Example:

      # good
      
      def some_method
        some_var = 1
        do_something(some_var)
      end

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

            if @item.contributors.empty?
              @item_contributors = []
            else
              @item_contributors = @item.contributors.all
            end
      Severity: Minor
      Found in lib/flagging_controller.rb by rubocop

      Use || instead of or.
      Open

            @at_least_a_moderator or @current_user == submitter or !@current_basket.fully_moderated?
      Severity: Minor
      Found in lib/flagging_controller.rb by rubocop

      This cop checks for uses of and and or, and suggests using && and || instead. It can be configured to check only in conditions, or in all contexts.

      Example: EnforcedStyle: always (default)

      # bad
      foo.save and return
      
      # bad
      if foo and bar
      end
      
      # good
      foo.save && return
      
      # good
      if foo && bar
      end

      Example: EnforcedStyle: conditionals

      # bad
      if foo and bar
      end
      
      # good
      foo.save && return
      
      # good
      foo.save and return
      
      # good
      if foo && bar
      end

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

            if !params[:message].blank? && !params[:message][0].blank?
              @message = params[:message][0]
            else
              @message = ''
            end
      Severity: Minor
      Found in lib/flagging_controller.rb by rubocop

      Use ! instead of not.
      Open

            if not @item.valid?
      Severity: Minor
      Found in lib/flagging_controller.rb by rubocop

      This cop checks for uses of the keyword not instead of !.

      Example:

      # bad - parentheses are required because of op precedence
      x = (not something)
      
      # good
      x = !something

      Favor unless over if for negative conditions.
      Open

            @submitter = @item.submitter_of(@version) if !@version.nil?
      Severity: Minor
      Found in lib/flagging_controller.rb by rubocop

      Checks for uses of if with a negated condition. Only ifs without else are considered. There are three different styles:

      - both
      - prefix
      - postfix

      Example: EnforcedStyle: both (default)

      # enforces `unless` for `prefix` and `postfix` conditionals
      
      # bad
      
      if !foo
        bar
      end
      
      # good
      
      unless foo
        bar
      end
      
      # bad
      
      bar if !foo
      
      # good
      
      bar unless foo

      Example: EnforcedStyle: prefix

      # enforces `unless` for just `prefix` conditionals
      
      # bad
      
      if !foo
        bar
      end
      
      # good
      
      unless foo
        bar
      end
      
      # good
      
      bar if !foo

      Example: EnforcedStyle: postfix

      # enforces `unless` for just `postfix` conditionals
      
      # bad
      
      bar if !foo
      
      # good
      
      bar unless foo
      
      # good
      
      if !foo
        bar
      end

      Use && instead of and.
      Open

              @versions = @item.versions.reject { |v| v.respond_to?(:private) and v.private? }
      Severity: Minor
      Found in lib/flagging_controller.rb by rubocop

      This cop checks for uses of and and or, and suggests using && and || instead. It can be configured to check only in conditions, or in all contexts.

      Example: EnforcedStyle: always (default)

      # bad
      foo.save and return
      
      # bad
      if foo and bar
      end
      
      # good
      foo.save && return
      
      # good
      if foo && bar
      end

      Example: EnforcedStyle: conditionals

      # bad
      if foo and bar
      end
      
      # good
      foo.save && return
      
      # good
      foo.save and return
      
      # good
      if foo && bar
      end

      Use || instead of or.
      Open

            @at_least_a_moderator or @current_user == submitter or !@current_basket.fully_moderated?
      Severity: Minor
      Found in lib/flagging_controller.rb by rubocop

      This cop checks for uses of and and or, and suggests using && and || instead. It can be configured to check only in conditions, or in all contexts.

      Example: EnforcedStyle: always (default)

      # bad
      foo.save and return
      
      # bad
      if foo and bar
      end
      
      # good
      foo.save && return
      
      # good
      if foo && bar
      end

      Example: EnforcedStyle: conditionals

      # bad
      if foo and bar
      end
      
      # good
      foo.save && return
      
      # good
      foo.save and return
      
      # good
      if foo && bar
      end

      Favor unless over if for negative conditions.
      Open

            @item.revert_to(params[:version]) if !params[:version].blank?
      Severity: Minor
      Found in lib/flagging_controller.rb by rubocop

      Checks for uses of if with a negated condition. Only ifs without else are considered. There are three different styles:

      - both
      - prefix
      - postfix

      Example: EnforcedStyle: both (default)

      # enforces `unless` for `prefix` and `postfix` conditionals
      
      # bad
      
      if !foo
        bar
      end
      
      # good
      
      unless foo
        bar
      end
      
      # bad
      
      bar if !foo
      
      # good
      
      bar unless foo

      Example: EnforcedStyle: prefix

      # enforces `unless` for just `prefix` conditionals
      
      # bad
      
      if !foo
        bar
      end
      
      # good
      
      unless foo
        bar
      end
      
      # good
      
      bar if !foo

      Example: EnforcedStyle: postfix

      # enforces `unless` for just `postfix` conditionals
      
      # bad
      
      bar if !foo
      
      # good
      
      bar unless foo
      
      # good
      
      if !foo
        bar
      end

      Favor unless over if for negative conditions.
      Open

                @flag_messages << tagging.message if !tagging.message.blank?
      Severity: Minor
      Found in lib/flagging_controller.rb by rubocop

      Checks for uses of if with a negated condition. Only ifs without else are considered. There are three different styles:

      - both
      - prefix
      - postfix

      Example: EnforcedStyle: both (default)

      # enforces `unless` for `prefix` and `postfix` conditionals
      
      # bad
      
      if !foo
        bar
      end
      
      # good
      
      unless foo
        bar
      end
      
      # bad
      
      bar if !foo
      
      # good
      
      bar unless foo

      Example: EnforcedStyle: prefix

      # enforces `unless` for just `prefix` conditionals
      
      # bad
      
      if !foo
        bar
      end
      
      # good
      
      unless foo
        bar
      end
      
      # good
      
      bar if !foo

      Example: EnforcedStyle: postfix

      # enforces `unless` for just `postfix` conditionals
      
      # bad
      
      bar if !foo
      
      # good
      
      bar unless foo
      
      # good
      
      if !foo
        bar
      end

      Favor a normal if-statement over a modifier clause in a multiline statement.
      Open

            @item.private_version do
              @current_private_version = @item.version
            end if @item.respond_to?(:private_version)
      Severity: Minor
      Found in lib/flagging_controller.rb by rubocop

      Checks for uses of if/unless modifiers with multiple-lines bodies.

      Example:

      # bad
      {
        result: 'this should not happen'
      } unless cond
      
      # good
      { result: 'ok' } if cond

      end at 19, 28 is not aligned with case at 12, 8.
      Open

                                  end
      Severity: Minor
      Found in lib/flagging_controller.rb by rubocop

      This cop checks whether the end keywords are aligned properly.

      Three modes are supported through the EnforcedStyleAlignWith configuration parameter:

      If it's set to keyword (which is the default), the end shall be aligned with the start of the keyword (if, class, etc.).

      If it's set to variable the end shall be aligned with the left-hand-side of the variable assignment, if there is one.

      If it's set to start_of_line, the end shall be aligned with the start of the line where the matching keyword appears.

      Example: EnforcedStyleAlignWith: keyword (default)

      # bad
      
      variable = if true
          end
      
      # good
      
      variable = if true
                 end

      Example: EnforcedStyleAlignWith: variable

      # bad
      
      variable = if true
          end
      
      # good
      
      variable = if true
      end

      Example: EnforcedStyleAlignWith: startofline

      # bad
      
      variable = if true
          end
      
      # good
      
      puts(if true
      end)

      There are no issues that match your filters.

      Category
      Status