otwcode/otwarchive

View on GitHub
app/controllers/comments_controller.rb

Summary

Maintainability
F
3 days
Test Coverage

File comments_controller.rb has 562 lines of code (exceeds 250 allowed). Consider refactoring.
Open

class CommentsController < ApplicationController
  skip_before_action :store_location, except: [:show, :index, :new]
  before_action :load_commentable,
                only: [:index, :new, :create, :edit, :update, :show_comments,
                       :hide_comments, :add_comment_reply,
Severity: Major
Found in app/controllers/comments_controller.rb - About 1 day to fix

    Class CommentsController has 51 methods (exceeds 20 allowed). Consider refactoring.
    Open

    class CommentsController < ApplicationController
      skip_before_action :store_location, except: [:show, :index, :new]
      before_action :load_commentable,
                    only: [:index, :new, :create, :edit, :update, :show_comments,
                           :hide_comments, :add_comment_reply,
    Severity: Major
    Found in app/controllers/comments_controller.rb - About 7 hrs to fix

      Method create has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
      Open

        def create
          if @commentable.nil?
            flash[:error] = ts("What did you want to comment on?")
            redirect_back_or_default(root_path)
          else
      Severity: Minor
      Found in app/controllers/comments_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 review has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

        def review
          if logged_in_as_admin?
            authorize @comment
          else
            return unless current_user_owns?(@comment.ultimate_parent)
      Severity: Minor
      Found in app/controllers/comments_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 create has 35 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def create
          if @commentable.nil?
            flash[:error] = ts("What did you want to comment on?")
            redirect_back_or_default(root_path)
          else
      Severity: Minor
      Found in app/controllers/comments_controller.rb - About 1 hr to fix

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

          def redirect_to_comment(comment, options = {})
            if comment.depth > ArchiveConfig.COMMENT_THREAD_MAX_DEPTH
              if comment.ultimate_parent.is_a?(Tag)
                default_options = {
                   controller: :comments,
        Severity: Minor
        Found in app/controllers/comments_controller.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 load_commentable has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

          def load_commentable
            @thread_view = false
            if params[:comment_id]
              @thread_view = true
              if params[:id]
        Severity: Minor
        Found in app/controllers/comments_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 destroy has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

          def destroy
            authorize @comment if logged_in_as_admin?
        
            parent = @comment.ultimate_parent
            parent_comment = @comment.reply_comment? ? @comment.commentable : nil
        Severity: Minor
        Found in app/controllers/comments_controller.rb - About 35 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 update has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

          def update
            updated_comment_params = comment_params.merge(edited_at: Time.current)
            if @comment.update(updated_comment_params)
              flash[:comment_notice] = ts('Comment was successfully updated.')
              respond_to do |format|
        Severity: Minor
        Found in app/controllers/comments_controller.rb - About 35 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 new has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

          def new
            if @commentable.nil?
              flash[:error] = ts("What did you want to comment on?")
              redirect_back_or_default(root_path)
            else
        Severity: Minor
        Found in app/controllers/comments_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

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

          def delete_comment
            respond_to do |format|
              format.html do
                options = {}
                options[:show_comments] = params[:show_comments] if params[:show_comments]
        Severity: Minor
        Found in app/controllers/comments_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

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

          def check_permission_to_moderate
            parent = find_parent
            unless logged_in_as_admin? || current_user_owns?(parent)
              flash[:error] = ts("Sorry, you don't have permission to moderate that comment.")
              redirect_to(logged_in? ? root_path : new_user_session_path)
        Severity: Minor
        Found in app/controllers/comments_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

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

          def review_all
            authorize @commentable, policy_class: CommentPolicy if logged_in_as_admin?
            unless (@commentable && current_user_owns?(@commentable)) || (@commentable && logged_in_as_admin? && @commentable.is_a?(AdminPost))
              flash[:error] = ts("What did you want to review comments on?")
              redirect_back_or_default(root_path)
        Severity: Minor
        Found in app/controllers/comments_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

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

          def check_parent_comment_permissions
            parent = find_parent
            if parent.is_a?(Work)
              translation_key = "work"
            elsif parent.is_a?(AdminPost)
        Severity: Minor
        Found in app/controllers/comments_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

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

          def check_permission_to_access_single_unreviewed
            return unless @comment.unreviewed?
            parent = find_parent
            return if logged_in_as_admin? || current_user_owns?(parent) || current_user_owns?(@comment)
            flash[:error] = ts("Sorry, that comment is currently in moderation.")
        Severity: Minor
        Found in app/controllers/comments_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

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

          def show_comments
            respond_to do |format|
              format.html do
                # if non-ajax it could mean sudden javascript failure OR being redirected from login
                # so we're being extra-nice and preserving any intention to comment along with the show comments option
        Severity: Minor
        Found in app/controllers/comments_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

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

          def check_parent
            parent = find_parent
            # Only admins and the owner can see comments on something hidden by an admin.
            if parent.respond_to?(:hidden_by_admin) && parent.hidden_by_admin
              logged_in_as_admin? || current_user_owns?(parent) || access_denied(redirect: root_path)
        Severity: Minor
        Found in app/controllers/comments_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

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

          def redirect_to_all_comments(commentable, options = {})
            default_options = {anchor: "comments"}
            options = default_options.merge(options)
        
            if commentable.is_a?(Tag)
        Severity: Minor
        Found in app/controllers/comments_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

        There are no issues that match your filters.

        Category
        Status