openjaf/cenit

View on GitHub
app/controllers/file_controller.rb

Summary

Maintainability
D
1 day
Test Coverage

Method index has a Cognitive Complexity of 57 (exceeds 5 allowed). Consider refactoring.
Open

  def index
    if (tenant = Tenant.where(id: params[:tenant_id]).first)
      tenant.switch do
        model = nil
        if (model_desc = params[:model])
Severity: Minor
Found in app/controllers/file_controller.rb - About 1 day 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 public has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
Open

  def public
    if (tenant = Tenant.where(id: params[:tenant_id]).first)
      tenant.switch do
        if (data_type = Setup::FileDataType.where(id: params[:data_type_id]).first)
          if data_type.public_read
Severity: Minor
Found in app/controllers/file_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 index has 44 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def index
    if (tenant = Tenant.where(id: params[:tenant_id]).first)
      tenant.switch do
        model = nil
        if (model_desc = params[:model])
Severity: Minor
Found in app/controllers/file_controller.rb - About 1 hr to fix

    Avoid deeply nested control flow statements.
    Open

                  if (filename.nil? || (uploader = find_version(uploader, uploader.path_for(record, field, filename)))) &&
                    (content = uploader.read)
                    send_data content,
                              filename: uploader.identifier,
                              type: uploader.file.content_type,
    Severity: Major
    Found in app/controllers/file_controller.rb - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

                    if (filename = params[:file])
                      filename = "#{filename}.#{params[:format]}" if params[:format]
                    end
      Severity: Major
      Found in app/controllers/file_controller.rb - About 45 mins to fix

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

          def find_version(uploader, path)
            if uploader.path == path
              uploader
            else
              uploader.versions.values.each do |uploader_version|
        Severity: Minor
        Found in app/controllers/file_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