redmine/redmine

View on GitHub
app/controllers/attachments_controller.rb

Summary

Maintainability
C
1 day
Test Coverage

Method show has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
Open

  def show
    respond_to do |format|
      format.html do
        if @attachment.container.respond_to?(:attachments)
          @attachments = @attachment.container.attachments.to_a
Severity: Minor
Found in app/controllers/attachments_controller.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

Class AttachmentsController has 24 methods (exceeds 20 allowed). Consider refactoring.
Open

class AttachmentsController < ApplicationController
  include ActionView::Helpers::NumberHelper

  before_action :find_attachment, :only => [:show, :download, :thumbnail, :update, :destroy]
  before_action :find_container, :only => [:edit_all, :update_all, :download_all]
Severity: Minor
Found in app/controllers/attachments_controller.rb - About 2 hrs to fix

    File attachments_controller.rb has 253 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    class AttachmentsController < ApplicationController
      include ActionView::Helpers::NumberHelper
    
      before_action :find_attachment, :only => [:show, :download, :thumbnail, :update, :destroy]
      before_action :find_container, :only => [:edit_all, :update_all, :download_all]
    Severity: Minor
    Found in app/controllers/attachments_controller.rb - About 2 hrs to fix

      Method show has 30 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def show
          respond_to do |format|
            format.html do
              if @attachment.container.respond_to?(:attachments)
                @attachments = @attachment.container.attachments.to_a
      Severity: Minor
      Found in app/controllers/attachments_controller.rb - About 1 hr to fix

        Method upload has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

          def upload
            # Make sure that API users get used to set this content type
            # as it won't trigger Rails' automatic parsing of the request body for parameters
            unless request.media_type == 'application/octet-stream'
              head 406
        Severity: Minor
        Found in app/controllers/attachments_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 find_container has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

          def find_container
            # object_type is constrained to valid values in routes
            klass = params[:object_type].to_s.singularize.classify.constantize
            @container = klass.find(params[:object_id])
            unless @container.visible?
        Severity: Minor
        Found in app/controllers/attachments_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