SpeciesFileGroup/taxonworks

View on GitHub
app/controllers/asserted_distributions_controller.rb

Summary

Maintainability
B
5 hrs
Test Coverage

Possible unprotected redirect
Open

        format.html { redirect_to @asserted_distribution, notice: 'Asserted distribution was successfully updated.' }

Unvalidated redirects and forwards are #10 on the OWASP Top Ten.

Redirects which rely on user-supplied values can be used to "spoof" websites or hide malicious links in otherwise harmless-looking URLs. They can also allow access to restricted areas of a site if the destination is not validated.

Brakeman will raise warnings whenever redirect_to appears to be used with a user-supplied value that may allow them to change the :host option.

For example,

redirect_to params.merge(:action => :home)

will create a warning like

Possible unprotected redirect near line 46: redirect_to(params)

This is because params could contain :host => 'evilsite.com' which would redirect away from your site and to a malicious site.

If the first argument to redirect_to is a hash, then adding :only_path => true will limit the redirect to the current host. Another option is to specify the host explicitly.

redirect_to params.merge(:only_path => true)

redirect_to params.merge(:host => 'myhost.com')

If the first argument is a string, then it is possible to parse the string and extract the path:

redirect_to URI.parse(some_url).path

If the URL does not contain a protocol (e.g., http://), then you will probably get unexpected results, as redirect_to will prepend the current host name and a protocol.

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

  def create_simple_batch_load
    if params[:file] && digested_cookie_exists?(params[:file].tempfile, :batch_asserted_distributions_md5)
      @result =  BatchLoad::Import::AssertedDistributions.new(**batch_params)
      if @result.create
        flash[:notice] = "Successfully proccessed file, #{@result.total_records_created} asserted distributions were created."
Severity: Minor
Found in app/controllers/asserted_distributions_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

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

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

create returns a model which is always truthy.
Open

      if @result.create

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

TODO found
Open

  # TODO: deprecate

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

  def create_simple_batch_load
    if params[:file] && digested_cookie_exists?(params[:file].tempfile, :batch_asserted_distributions_md5)
      @result =  BatchLoad::Import::AssertedDistributions.new(**batch_params)
      if @result.create
        flash[:notice] = "Successfully proccessed file, #{@result.total_records_created} asserted distributions were created."
Severity: Major
Found in app/controllers/asserted_distributions_controller.rb and 2 other locations - About 1 hr to fix
app/controllers/collecting_events_controller.rb on lines 180..193
app/controllers/taxon_names_controller.rb on lines 173..186

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

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

  def create
    @asserted_distribution = AssertedDistribution.new(asserted_distribution_params)
    respond_to do |format|
      if @asserted_distribution.save
        format.html { redirect_to @asserted_distribution, notice: 'Asserted distribution was successfully created.' }
Severity: Major
Found in app/controllers/asserted_distributions_controller.rb and 21 other locations - About 1 hr to fix
app/controllers/attributions_controller.rb on lines 42..51
app/controllers/biological_associations_controller.rb on lines 45..53
app/controllers/biological_associations_graphs_controller.rb on lines 44..53
app/controllers/biological_relationships_controller.rb on lines 61..70
app/controllers/character_states_controller.rb on lines 29..38
app/controllers/collection_object_observations_controller.rb on lines 30..40
app/controllers/collection_profiles_controller.rb on lines 33..42
app/controllers/common_names_controller.rb on lines 46..55
app/controllers/dataset_records_controller.rb on lines 28..37
app/controllers/depictions_controller.rb on lines 71..79
app/controllers/extracts_controller.rb on lines 44..53
app/controllers/gene_attributes_controller.rb on lines 33..42
app/controllers/loans_controller.rb on lines 49..58
app/controllers/observation_matrices_controller.rb on lines 47..56
app/controllers/organizations_controller.rb on lines 36..45
app/controllers/origin_relationships_controller.rb on lines 43..52
app/controllers/otu_page_layouts_controller.rb on lines 31..40
app/controllers/protocol_relationships_controller.rb on lines 47..56
app/controllers/protocols_controller.rb on lines 40..49
app/controllers/ranged_lot_categories_controller.rb on lines 29..38
app/controllers/sequences_controller.rb on lines 38..47

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

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

  def update
    respond_to do |format|
      if @asserted_distribution.update(asserted_distribution_params)
        format.html { redirect_to @asserted_distribution, notice: 'Asserted distribution was successfully updated.' }
        format.json { render :show, status: :ok, location: @asserted_distribution }
Severity: Major
Found in app/controllers/asserted_distributions_controller.rb and 22 other locations - About 55 mins to fix
app/controllers/attributions_controller.rb on lines 58..65
app/controllers/biological_associations_controller.rb on lines 60..67
app/controllers/biological_associations_graphs_controller.rb on lines 60..67
app/controllers/biological_relationships_controller.rb on lines 77..84
app/controllers/character_states_controller.rb on lines 45..52
app/controllers/collection_object_observations_controller.rb on lines 47..55
app/controllers/common_names_controller.rb on lines 62..69
app/controllers/confidences_controller.rb on lines 55..62
app/controllers/depictions_controller.rb on lines 86..93
app/controllers/documents_controller.rb on lines 45..52
app/controllers/extracts_controller.rb on lines 60..67
app/controllers/gene_attributes_controller.rb on lines 49..56
app/controllers/images_controller.rb on lines 87..94
app/controllers/observation_matrices_controller.rb on lines 63..70
app/controllers/organizations_controller.rb on lines 52..59
app/controllers/origin_relationships_controller.rb on lines 59..66
app/controllers/otu_page_layouts_controller.rb on lines 47..54
app/controllers/protocol_relationships_controller.rb on lines 63..70
app/controllers/protocols_controller.rb on lines 56..63
app/controllers/ranged_lot_categories_controller.rb on lines 45..52
app/controllers/sequences_controller.rb on lines 54..61
app/controllers/type_materials_controller.rb on lines 58..65

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

  def index
    respond_to do |format|
      format.html {
        @recent_objects = AssertedDistribution.recent_from_project_id(sessions_current_project_id)
          .order(updated_at: :desc)
Severity: Minor
Found in app/controllers/asserted_distributions_controller.rb and 1 other location - About 55 mins to fix
app/controllers/observation_matrices_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 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 5 locations. Consider refactoring.
Open

  def batch_update
    if r = AssertedDistribution.batch_update(
        preview: params[:preview], 
        asserted_distribution: asserted_distribution_params.merge(by: sessions_current_user_id),
        asserted_distribution_query: params[:asserted_distribution_query],
Severity: Major
Found in app/controllers/asserted_distributions_controller.rb and 4 other locations - About 35 mins to fix
app/controllers/biological_associations_controller.rb on lines 153..161
app/controllers/collecting_events_controller.rb on lines 128..136
app/controllers/collection_objects_controller.rb on lines 402..410
app/controllers/otus_controller.rb on lines 254..263

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

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

  def preview_simple_batch_load
    if params[:file]
      @result =  BatchLoad::Import::AssertedDistributions.new(**batch_params)
      digest_cookie(params[:file].tempfile, :batch_asserted_distributions_md5)
      render 'asserted_distributions/batch_load/simple/preview'
Severity: Minor
Found in app/controllers/asserted_distributions_controller.rb and 2 other locations - About 30 mins to fix
app/controllers/collecting_events_controller.rb on lines 169..177
app/controllers/taxon_names_controller.rb on lines 162..170

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

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