SpeciesFileGroup/taxonworks

View on GitHub
app/controllers/data_attributes_controller.rb

Summary

Maintainability
B
4 hrs
Test Coverage

Class DataAttributesController has 23 methods (exceeds 20 allowed). Consider refactoring.
Open

class DataAttributesController < ApplicationController
  include DataControllerConfiguration::ProjectDataControllerConfiguration

  before_action :set_data_attribute, only: [:update, :destroy, :api_show]
  after_action -> { set_pagination_headers(:data_attributes) }, only: [:index, :api_index ], if: :json_request?
Severity: Minor
Found in app/controllers/data_attributes_controller.rb - About 2 hrs to fix

    Use destroy! instead of destroy if the return value is not checked.
    Open

        @data_attribute.destroy

    This cop identifies possible cases where Active Record save! or related should be used instead of save because the model might have failed to save and an exception is better than unhandled failure.

    This will allow: - update or save calls, assigned to a variable, or used as a condition in an if/unless/case statement. - create calls, assigned to a variable that then has a call to persisted?. - calls if the result is explicitly returned from methods and blocks, or provided as arguments. - calls whose signature doesn't look like an ActiveRecord persistence method.

    By default it will also allow implicit returns from methods and blocks. that behavior can be turned off with AllowImplicitReturn: false.

    You can permit receivers that are giving false positives with AllowedReceivers: []

    Example:

    # bad
    user.save
    user.update(name: 'Joe')
    user.find_or_create_by(name: 'Joe')
    user.destroy
    
    # good
    unless user.save
      # ...
    end
    user.save!
    user.update!(name: 'Joe')
    user.find_or_create_by!(name: 'Joe')
    user.destroy!
    
    user = User.find_or_create_by(name: 'Joe')
    unless user.persisted?
      # ...
    end
    
    def save_user
      return user.save
    end

    Example: AllowImplicitReturn: true (default)

    # good
    users.each { |u| u.save }
    
    def save_user
      user.save
    end

    Example: AllowImplicitReturn: false

    # bad
    users.each { |u| u.save }
    def save_user
      user.save
    end
    
    # good
    users.each { |u| u.save! }
    
    def save_user
      user.save!
    end
    
    def save_user
      return user.save
    end

    Example: AllowedReceivers: ['merchant.customers', 'Service::Mailer']

    # bad
    merchant.create
    customers.builder.save
    Mailer.create
    
    module Service::Mailer
      self.create
    end
    
    # good
    merchant.customers.create
    MerchantService.merchant.customers.destroy
    Service::Mailer.update(message: 'Message')
    ::Service::Mailer.update
    Services::Service::Mailer.update(message: 'Message')
    Service::Mailer::update

    Use find_by instead of dynamic find_by_id.
    Open

        @data_attribute = DataAttribute.find_by_id(params[:id])

    This cop checks dynamic find_by_* methods. Use find_by instead of dynamic method. See. https://github.com/rubocop-hq/rails-style-guide#find_by

    Example:

    # bad
    User.find_by_name(name)
    
    # bad
    User.find_by_name_and_email(name)
    
    # bad
    User.find_by_email!(name)
    
    # good
    User.find_by(name: name)
    
    # good
    User.find_by(name: name, email: email)
    
    # good
    User.find_by!(email: email)

    TODO found
    Open

      # TODO: /brief differs in that the first value is id, determine whether we should do that in /api

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

      def index
        respond_to do |format|
          format.html {
            @recent_objects = DataAttribute.where(project_id: sessions_current_project_id).order(updated_at: :desc).limit(10)
            render '/shared/data/all/index'
    Severity: Major
    Found in app/controllers/data_attributes_controller.rb and 2 other locations - About 50 mins to fix
    app/controllers/collecting_events_controller.rb on lines 9..18
    app/controllers/notes_controller.rb on lines 12..22

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

    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

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

        @columns = Predicate.where(project_id: sessions_current_project_id, id: cols).order(:name).pluck(:id, :name).inject([]){|ary, a| ary.push(a[0] => a[1]); ary}
    Severity: Minor
    Found in app/controllers/data_attributes_controller.rb and 1 other location - About 20 mins to fix
    app/controllers/data_attributes_controller.rb on lines 31..31

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

    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

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

        @columns = Predicate.where(project_id: sessions_current_project_id, id: cols).order(:name).pluck(:id, :name).inject([]){|ary, a| ary.push(a[0] => a[1]); ary}
    Severity: Minor
    Found in app/controllers/data_attributes_controller.rb and 1 other location - About 20 mins to fix
    app/controllers/data_attributes_controller.rb on lines 43..43

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

    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 4 locations. Consider refactoring.
    Open

      def api_index
        @data_attributes = Queries::DataAttribute::Filter.new(params.merge!(api: true)).all
          .where(project_id: sessions_current_project_id)
          .page(params[:page])
          .per(params[:per])
    Severity: Minor
    Found in app/controllers/data_attributes_controller.rb and 3 other locations - About 20 mins to fix
    app/controllers/controlled_vocabulary_terms_controller.rb on lines 133..138
    app/controllers/images_controller.rb on lines 39..43
    app/controllers/observation_matrices_controller.rb on lines 239..244

    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

      def autocomplete
        render json: {} and return if params[:term].blank?
    
        @data_attributes = Queries::DataAttribute::Autocomplete.new(
          params.require(:term),
    Severity: Minor
    Found in app/controllers/data_attributes_controller.rb and 1 other location - About 15 mins to fix
    app/controllers/notes_controller.rb on lines 98..100

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

    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