fairplaysk/datacamp

View on GitHub
app/controllers/datasets_controller.rb

Summary

Maintainability
D
2 days
Test Coverage

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

  def show
    @dataset_description = DatasetDescription.find(params[:id])
    @field_descriptions  = @dataset_description.visible_field_descriptions.includes(:data_format)
    @dataset_class       = @dataset_description.dataset_model
    @title               = @dataset_description.title
Severity: Minor
Found in app/controllers/datasets_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 show has 97 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def show
    @dataset_description = DatasetDescription.find(params[:id])
    @field_descriptions  = @dataset_description.visible_field_descriptions.includes(:data_format)
    @dataset_class       = @dataset_description.dataset_model
    @title               = @dataset_description.title
Severity: Major
Found in app/controllers/datasets_controller.rb - About 3 hrs to fix

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

      def update
        @dataset_description  = DatasetDescription.find_by_id(params[:id])
        @dataset_class        = @dataset_description.dataset_model
    
        if params[:record].blank?
    Severity: Minor
    Found in app/controllers/datasets_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 update has 32 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def update
        @dataset_description  = DatasetDescription.find_by_id(params[:id])
        @dataset_class        = @dataset_description.dataset_model
    
        if params[:record].blank?
    Severity: Minor
    Found in app/controllers/datasets_controller.rb - About 1 hr to fix

      Avoid deeply nested control flow statements.
      Open

                  if @filters['quality_status'] == 'absent'
                    @dataset_class = @dataset_class.where('quality_status IS NULL OR quality_status = ?', @filters['quality_status'])
                  else
                    @dataset_class = @dataset_class.where(quality_status: @filters['quality_status'])
                  end
      Severity: Major
      Found in app/controllers/datasets_controller.rb - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                    if @filters['quality_status'] == 'absent'
                      @dataset_class = @dataset_class.where('t.quality_status IS NULL OR t.quality_status = ?', @filters['quality_status'])
                    else
                      @dataset_class = @dataset_class.where('t.quality_status = ?', @filters['quality_status'])
                    end
        Severity: Major
        Found in app/controllers/datasets_controller.rb - About 45 mins to fix

          There are no issues that match your filters.

          Category
          Status