SpeciesFileGroup/taxonworks

View on GitHub
app/controllers/observations_controller.rb

Summary

Maintainability
B
5 hrs
Test Coverage

Method has too many lines. [30/25]
Open

  def observation_params
    params.require(:observation).permit(
      :character_state_id, :frequency,
      :continuous_value, :continuous_unit,
      :day_made,

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

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

  def observation_params
    params.require(:observation).permit(
      :character_state_id, :frequency,
      :continuous_value, :continuous_unit,
      :day_made,
Severity: Minor
Found in app/controllers/observations_controller.rb - About 1 hr to fix

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

        @observation.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

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

      def create
        @observation = Observation.new(observation_params)
        respond_to do |format|
          if @observation.save
            format.html {
    Severity: Major
    Found in app/controllers/observations_controller.rb and 1 other location - About 1 hr to fix
    app/controllers/descriptors_controller.rb on lines 47..56

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

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

      def destroy
        @observation.destroy
        respond_to do |format|
          if @observation.destroyed?
            format.html { destroy_redirect @observation, notice: 'Observation was successfully destroyed.' }
    Severity: Major
    Found in app/controllers/observations_controller.rb and 15 other locations - About 1 hr to fix
    app/controllers/citations_controller.rb on lines 86..94
    app/controllers/collecting_events_controller.rb on lines 82..90
    app/controllers/containers_controller.rb on lines 71..79
    app/controllers/contents_controller.rb on lines 67..75
    app/controllers/controlled_vocabulary_terms_controller.rb on lines 63..71
    app/controllers/descriptors_controller.rb on lines 84..92
    app/controllers/downloads_controller.rb on lines 36..44
    app/controllers/georeferences_controller.rb on lines 123..131
    app/controllers/otus_controller.rb on lines 101..109
    app/controllers/people_controller.rb on lines 71..79
    app/controllers/sequence_relationships_controller.rb on lines 66..74
    app/controllers/tags_controller.rb on lines 91..99
    app/controllers/taxon_name_classifications_controller.rb on lines 92..100
    app/controllers/taxon_name_relationships_controller.rb on lines 73..81
    app/controllers/taxon_names_controller.rb on lines 73..81

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

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

      def index
        respond_to do |format|
          format.html do
            @recent_objects = Observation.recent_from_project_id(sessions_current_project_id)
              .order(updated_at: :desc).limit(10)
    Severity: Major
    Found in app/controllers/observations_controller.rb and 4 other locations - About 55 mins to fix
    app/controllers/biological_associations_controller.rb on lines 9..20
    app/controllers/extracts_controller.rb on lines 9..19
    app/controllers/georeferences_controller.rb on lines 8..18
    app/controllers/images_controller.rb on lines 9..18

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

    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

          if @observation.update(observation_params)
            format.html { redirect_to url_for(@observation.metamorphosize),
                          notice: 'Observation was successfully updated.' }
            format.json { render :show, status: :ok, location: @observation.metamorphosize }
          else
    Severity: Minor
    Found in app/controllers/observations_controller.rb and 1 other location - About 50 mins to fix
    app/controllers/descriptors_controller.rb on lines 66..72

    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

      def destroy_row
        @observation_matrix_row = ObservationMatrixRow.where(project_id: sessions_current_project_id).find(params.require(:observation_matrix_row_id))
        if Observation.destroy_row(@observation_matrix_row.id)
          render json: {success: true}
        else
    Severity: Minor
    Found in app/controllers/observations_controller.rb and 1 other location - About 25 mins to fix
    app/controllers/observations_controller.rb on lines 116..122

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

    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 destroy_column
        @observation_matrix_column = ObservationMatrixColumn.where(project_id: sessions_current_project_id).find(params.require(:observation_matrix_column_id))
        if Observation.destroy_column(@observation_matrix_column.id)
          render json: {success: true}
        else
    Severity: Minor
    Found in app/controllers/observations_controller.rb and 1 other location - About 25 mins to fix
    app/controllers/observations_controller.rb on lines 106..112

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

    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