ChaelCodes/HuntersKeepers

View on GitHub
app/controllers/hunter_backstories_controller.rb

Summary

Maintainability
A
0 mins
Test Coverage

Parameters should be whitelisted for mass assignment
Wontfix

              params[:hunter_backstory]

Mass assignment is a feature of Rails which allows an application to create a record from the values of a hash.

Example:

User.new(params[:user])

Unfortunately, if there is a user field called admin which controls administrator access, now any user can make themselves an administrator.

attr_accessible and attr_protected can be used to limit mass assignment. However, Brakeman will warn unless attr_accessible is used, or mass assignment is completely disabled.

There are two different mass assignment warnings which can arise. The first is when mass assignment actually occurs, such as the example above. This results in a warning like

Unprotected mass assignment near line 61: User.new(params[:user])

The other warning is raised whenever a model is found which does not use attr_accessible. This produces generic warnings like

Mass assignment is not restricted using attr_accessible

with a list of affected models.

In Rails 3.1 and newer, mass assignment can easily be disabled:

config.active_record.whitelist_attributes = true

Unfortunately, it can also easily be bypassed:

User.new(params[:user], :without_protection => true)

Brakeman will warn on uses of without_protection.

Method has too many lines. [11/10]
Wontfix

  def create
    @hunter_backstory = HunterBackstory.new(hunter_backstory_params)
    authorize @hunter_backstory
    respond_to do |format|
      if @hunter_backstory.save

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.

Assignment Branch Condition size for create is too high. [15.17/15]
Wontfix

  def create
    @hunter_backstory = HunterBackstory.new(hunter_backstory_params)
    authorize @hunter_backstory
    respond_to do |format|
      if @hunter_backstory.save

This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric and https://en.wikipedia.org/wiki/ABC_Software_Metric.

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

  def create
    @hunter_backstory = HunterBackstory.new(hunter_backstory_params)
    authorize @hunter_backstory
    respond_to do |format|
      if @hunter_backstory.save
Severity: Major
Found in app/controllers/hunter_backstories_controller.rb and 1 other location - About 1 hr to fix
app/controllers/playbooks_controller.rb on lines 28..37

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

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

  def update
    respond_to do |format|
      if @hunter_backstory.update(hunter_backstory_params)
        format.html { redirect_to @hunter_backstory, notice: t('.success') }
        format.json { render :show, status: :ok, location: @hunter_backstory }
Severity: Minor
Found in app/controllers/hunter_backstories_controller.rb and 1 other location - About 55 mins to fix
app/controllers/playbooks_controller.rb on lines 44..51

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

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

Line is too long. [92/80]
Wontfix

        format.json { render json: @hunter_backstory.errors, status: :unprocessable_entity }

Line is too long. [83/80]
Wontfix

        format.json { render :show, status: :created, location: @hunter_backstory }

Line is too long. [92/80]
Wontfix

        format.json { render json: @hunter_backstory.errors, status: :unprocessable_entity }

There are no issues that match your filters.

Category
Status