SpeciesFileGroup/taxonworks

View on GitHub
app/controllers/papertrail_controller.rb

Summary

Maintainability
A
3 hrs
Test Coverage

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

  def update
    klass = whitelist_constantize(params.require(:object_type))
    @object = klass.find(params[:object_id])

    if invalid_object(@object)

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 update has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
Open

  def update
    klass = whitelist_constantize(params.require(:object_type))
    @object = klass.find(params[:object_id])

    if invalid_object(@object)
Severity: Minor
Found in app/controllers/papertrail_controller.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

Method update has 29 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def update
    klass = whitelist_constantize(params.require(:object_type))
    @object = klass.find(params[:object_id])

    if invalid_object(@object)
Severity: Minor
Found in app/controllers/papertrail_controller.rb - About 1 hr to fix

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

      def index
        respond_to do |format|
          format.html {
            redirect_to hub_path, notice: 'You requested a papertrail for nothing.' and return if params[:object_type].blank?
            klass = whitelist_constantize(params.require(:object_type))
    Severity: Minor
    Found in app/controllers/papertrail_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

    Prefer symbols instead of strings as hash keys.
    Open

          render head 404, "content_type" => 'text/plain' if o.respond_to?(:project_id) && o.project_id != sessions_current_project_id

    This cop checks for the use of strings as keys in hashes. The use of symbols is preferred instead.

    Example:

    # bad
    { 'one' => 1, 'two' => 2, 'three' => 3 }
    
    # good
    { one: 1, two: 2, three: 3 }

    Prefer single-quoted strings when you don't need string interpolation or special symbols.
    Open

          render head 404, "content_type" => 'text/plain' if o.respond_to?(:project_id) && o.project_id != sessions_current_project_id

    Checks if uses of quotes match the configured preference.

    Example: EnforcedStyle: single_quotes (default)

    # bad
    "No special symbols"
    "No string interpolation"
    "Just text"
    
    # good
    'No special symbols'
    'No string interpolation'
    'Just text'
    "Wait! What's #{this}!"

    Example: EnforcedStyle: double_quotes

    # bad
    'Just some text'
    'No special chars or interpolation'
    
    # good
    "Just some text"
    "No special chars or interpolation"
    "Every string in #{project} uses double_quotes"

    There are no issues that match your filters.

    Category
    Status