MiraitSystems/enju_trunk

View on GitHub
app/controllers/approvals_controller.rb

Summary

Maintainability
F
6 days
Test Coverage

Method output_csv has a Cognitive Complexity of 172 (exceeds 5 allowed). Consider refactoring.
Open

  def output_csv
    approvals = Approval.scoped
    # approval_identifier
    unless params[:approval_identifier].blank?
      approvals = approvals.where(["approvals.approval_identifier like ?", params[:approval_identifier] + "%"])
Severity: Minor
Found in app/controllers/approvals_controller.rb - About 3 days 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 output_csv has 164 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def output_csv
    approvals = Approval.scoped
    # approval_identifier
    unless params[:approval_identifier].blank?
      approvals = approvals.where(["approvals.approval_identifier like ?", params[:approval_identifier] + "%"])
Severity: Major
Found in app/controllers/approvals_controller.rb - About 6 hrs to fix

    File approvals_controller.rb has 351 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    class ApprovalsController < ApplicationController
      add_breadcrumb "I18n.t('page.listing', model: t('activerecord.models.approval'))", 'approvals_path'
      add_breadcrumb "I18n.t('page.new', model: I18n.t('activerecord.models.approval'))", 'new_approval_path', only: [:new, :create]
      add_breadcrumb "I18n.t('page.editing', :model => I18n.t('activerecord.models.approval'))", 'edit_approval_path(params[:id])', only: [:edit, :update]
      add_breadcrumb "I18n.t('activerecord.models.approval')", 'approval_path([:id])', only: [:show]
    Severity: Minor
    Found in app/controllers/approvals_controller.rb - About 4 hrs to fix

      Method get_approval_report has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
      Open

        def get_approval_report
          begin
            @approval = Approval.find(params[:param])
            case params[:output]
            when 'report'
      Severity: Minor
      Found in app/controllers/approvals_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

      Method search has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
      Open

        def search
      
          @approvals = Approval.scoped
      
          # approval_identifier
      Severity: Minor
      Found in app/controllers/approvals_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 get_approval_report has 49 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def get_approval_report
          begin
            @approval = Approval.find(params[:param])
            case params[:output]
            when 'report'
      Severity: Minor
      Found in app/controllers/approvals_controller.rb - About 1 hr to fix

        Method search has 41 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def search
        
            @approvals = Approval.scoped
        
            # approval_identifier
        Severity: Minor
        Found in app/controllers/approvals_controller.rb - About 1 hr to fix

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

            def create
          
              @approval = Approval.new(params[:approval])
              @approval.check_status
              @approval.identifier = params[:identifier] if params[:identifier]
          Severity: Minor
          Found in app/controllers/approvals_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

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

              unless params[:status].blank?
                if params[:status].include?("notset")
                  ids = params[:status].reject{|e| e == "notset"}
                  if ids.blank?
                    approvals = approvals.where("status IS NULL")
          Severity: Minor
          Found in app/controllers/approvals_controller.rb and 1 other location - About 50 mins to fix
          app/controllers/approvals_controller.rb on lines 248..257

          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 43.

          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

              unless params[:approval_result].blank?
                if params[:approval_result].include?("notset")
                  ids = params[:approval_result].reject{|e| e == "notset"}
                  if ids.blank?
                    @approvals = @approvals.where("approval_result IS NULL")
          Severity: Minor
          Found in app/controllers/approvals_controller.rb and 1 other location - About 50 mins to fix
          app/controllers/approvals_controller.rb on lines 179..188

          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 43.

          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

              unless params[:approval_result].blank?
                if params[:approval_result].include?("notset")
                  ids = params[:approval_result].reject{|e| e == "notset"}
                  if ids.blank?
                    approvals = approvals.where("approval_result IS NULL")
          Severity: Minor
          Found in app/controllers/approvals_controller.rb and 1 other location - About 50 mins to fix
          app/controllers/approvals_controller.rb on lines 234..243

          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 43.

          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

              unless params[:status].blank?
                if params[:status].include?("notset")
                  ids = params[:status].reject{|e| e == "notset"}
                  if ids.blank?
                    @approvals = @approvals.where("status IS NULL")
          Severity: Minor
          Found in app/controllers/approvals_controller.rb and 1 other location - About 50 mins to fix
          app/controllers/approvals_controller.rb on lines 193..202

          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 43.

          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

                        when "issn"
                          identifier_type = IdentifierType.where("name = 'issn'").first
                          identifiers = Identifier.where(["identifier_type_id = ? and manifestation_id = ?", identifier_type, approval.manifestation])
                          if identifiers.present?
                            detail << identifiers.first.body
          Severity: Minor
          Found in app/controllers/approvals_controller.rb and 1 other location - About 20 mins to fix
          app/controllers/approvals_controller.rb on lines 360..366

          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 27.

          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

                        when "jmas"
                          identifier_type = IdentifierType.where("name = 'jma'").first
                          identifiers = Identifier.where(["identifier_type_id = ? and manifestation_id = ?", identifier_type, approval.manifestation])
                          if identifiers.present?
                            detail << identifiers.first.body
          Severity: Minor
          Found in app/controllers/approvals_controller.rb and 1 other location - About 20 mins to fix
          app/controllers/approvals_controller.rb on lines 368..374

          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 27.

          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

          There are no issues that match your filters.

          Category
          Status