ece517-p3/expertiza

View on GitHub
app/models/tag_prompt.rb

Summary

Maintainability
A
2 hrs
Test Coverage

Mass assignment is not restricted using attr_accessible
Open

class TagPrompt < ActiveRecord::Base
Severity: Critical
Found in app/models/tag_prompt.rb by brakeman

This warning comes up if a model does not limit what attributes can be set through mass assignment.

In particular, this check looks for attr_accessible inside model definitions. If it is not found, this warning will be issued.

Brakeman also warns on use of attr_protected - especially since it was found to be vulnerable to bypass. Warnings for mass assignment on models using attr_protected will be reported, but at a lower confidence level.

Note that disabling mass assignment globally will suppress these warnings.

Assignment Branch Condition size for slider_control is too high. [53.94/15]
Open

  def slider_control(answer, tag_prompt_deployment, stored_tags)
    html = ""
    value = "0"
    if stored_tags.count > 0
      tag = stored_tags.first
Severity: Minor
Found in app/models/tag_prompt.rb by rubocop

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

Assignment Branch Condition size for checkbox_control is too high. [38.5/15]
Open

  def checkbox_control(answer, tag_prompt_deployment, stored_tags)
    html = ""
    value = "0"

    if stored_tags.count > 0
Severity: Minor
Found in app/models/tag_prompt.rb by rubocop

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

Assignment Branch Condition size for html_control is too high. [25.34/15]
Open

  def html_control(tag_prompt_deployment, answer, user_id)
    html = ""
    unless answer.nil?
      stored_tags = AnswerTag.where(tag_prompt_deployment_id: tag_prompt_deployment.id, answer_id: answer.id, user_id: user_id)

Severity: Minor
Found in app/models/tag_prompt.rb by rubocop

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

Cyclomatic complexity for html_control is too high. [9/6]
Open

  def html_control(tag_prompt_deployment, answer, user_id)
    html = ""
    unless answer.nil?
      stored_tags = AnswerTag.where(tag_prompt_deployment_id: tag_prompt_deployment.id, answer_id: answer.id, user_id: user_id)

Severity: Minor
Found in app/models/tag_prompt.rb by rubocop

This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.

Method html_control has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

  def html_control(tag_prompt_deployment, answer, user_id)
    html = ""
    unless answer.nil?
      stored_tags = AnswerTag.where(tag_prompt_deployment_id: tag_prompt_deployment.id, answer_id: answer.id, user_id: user_id)

Severity: Minor
Found in app/models/tag_prompt.rb - About 1 hr 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

Perceived complexity for html_control is too high. [9/7]
Open

  def html_control(tag_prompt_deployment, answer, user_id)
    html = ""
    unless answer.nil?
      stored_tags = AnswerTag.where(tag_prompt_deployment_id: tag_prompt_deployment.id, answer_id: answer.id, user_id: user_id)

Severity: Minor
Found in app/models/tag_prompt.rb by rubocop

This cop tries to produce a complexity score that's a measure of the complexity the reader experiences when looking at a method. For that reason it considers when nodes as something that doesn't add as much complexity as an if or a &&. Except if it's one of those special case/when constructs where there's no expression after case. Then the cop treats it as an if/elsif/elsif... and lets all the when nodes count. In contrast to the CyclomaticComplexity cop, this cop considers else nodes as adding complexity.

Example:

def my_method                   # 1
  if cond                       # 1
    case var                    # 2 (0.8 + 4 * 0.2, rounded)
    when 1 then func_one
    when 2 then func_two
    when 3 then func_three
    when 4..10 then func_other
    end
  else                          # 1
    do_something until a && b   # 2
  end                           # ===
end                             # 7 complexity points

Tagging a string as html safe may be a security risk.
Open

    html.html_safe
Severity: Minor
Found in app/models/tag_prompt.rb by rubocop

This cop checks for the use of output safety calls like htmlsafe, raw, and safeconcat. These methods do not escape content. They simply return a SafeBuffer containing the content as is. Instead, use safe_join to join content and escape it and concat to concatenate content and escape it, ensuring its safety.

Example:

user_content = "hi"

# bad
"

#{user_content}

".html_safe # => ActiveSupport::SafeBuffer "

hi

" # good content_tag(:p, user_content) # => ActiveSupport::SafeBuffer "

<b>hi</b>

" # bad out = "" out << "
  • #{user_content}
  • " out << "
  • #{user_content}
  • " out.html_safe # => ActiveSupport::SafeBuffer "
  • hi
  • hi
  • " # good out = [] out << content_tag(:li, user_content) out << content_tag(:li, user_content) safe_join(out) # => ActiveSupport::SafeBuffer # "
  • <b>hi</b>
  • <b>hi</b>
  • " # bad out = "

    trusted content

    ".html_safe out.safe_concat(user_content) # => ActiveSupport::SafeBuffer "

    trusted_content

    hi" # good out = "

    trusted content

    ".html_safe out.concat(user_content) # => ActiveSupport::SafeBuffer # "

    trusted_content

    <b>hi</b>" # safe, though maybe not good style out = "trusted content" result = out.concat(user_content) # => String "trusted contenthi" # because when rendered in ERB the String will be escaped: # <%= result %> # => trusted content<b>hi</b> # bad (user_content + " " + content_tag(:span, user_content)).html_safe # => ActiveSupport::SafeBuffer "hi <span><b>hi</b></span>" # good safe_join([user_content, " ", content_tag(:span, user_content)]) # => ActiveSupport::SafeBuffer # "<b>hi</b> <span>&lt;b&gt;hi&lt;/b&gt;</span>"

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

        html += '<input type="checkbox" name="tag_checkboxes[]" id="' + control_id + '" value="' + value + '" onLoad="toggleLabel(this)" onChange="toggleLabel(this); save_tag(' + answer.id.to_s + ', ' + tag_prompt_deployment.id.to_s + ', ' + control_id + ');" />'
        html += '<label for="' + control_id + '">&nbsp;'
    Severity: Minor
    Found in app/models/tag_prompt.rb and 1 other location - About 20 mins to fix
    app/models/tag_prompt.rb on lines 72..73

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

        html += '   <input type="range" name="tag_checkboxes[]" id="' + control_id + '" min="-1" class="rangeAll" max="1" value="' + value + '" onLoad="toggleLabel(this)" onChange="toggleLabel(this); save_tag(' + answer.id.to_s + ', ' + tag_prompt_deployment.id.to_s + ', ' + control_id + ');"></input>'
        html += ' </div>'
    Severity: Minor
    Found in app/models/tag_prompt.rb and 1 other location - About 20 mins to fix
    app/models/tag_prompt.rb on lines 43..44

    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

    Line is too long. [299/160]
    Open

        html += '   <input type="range" name="tag_checkboxes[]" id="' + control_id + '" min="-1" class="rangeAll" max="1" value="' + value + '" onLoad="toggleLabel(this)" onChange="toggleLabel(this); save_tag(' + answer.id.to_s + ', ' + tag_prompt_deployment.id.to_s + ', ' + control_id + ');"></input>'
    Severity: Minor
    Found in app/models/tag_prompt.rb by rubocop

    Line is too long. [259/160]
    Open

        html += '<input type="checkbox" name="tag_checkboxes[]" id="' + control_id + '" value="' + value + '" onLoad="toggleLabel(this)" onChange="toggleLabel(this); save_tag(' + answer.id.to_s + ', ' + tag_prompt_deployment.id.to_s + ', ' + control_id + ');" />'
    Severity: Minor
    Found in app/models/tag_prompt.rb by rubocop

    There are no issues that match your filters.

    Category
    Status