wearefine/fae

View on GitHub
app/models/fae/change.rb

Summary

Maintainability
B
4 hrs
Test Coverage

Assignment Branch Condition size for filter is too high. [56.18/15]
Open

      def filter(params)
        # build conditions if specific params are present
        conditions = {}
        conditions[:user_id] = params['user'] if params['user'].present?
        conditions[:changeable_type] = params['model'] if params['model'].present?
Severity: Minor
Found in app/models/fae/change.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

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

      def filter(params)
        # build conditions if specific params are present
        conditions = {}
        conditions[:user_id] = params['user'] if params['user'].present?
        conditions[:changeable_type] = params['model'] if params['model'].present?
Severity: Minor
Found in app/models/fae/change.rb by rubocop

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

      def filter(params)
        # build conditions if specific params are present
        conditions = {}
        conditions[:user_id] = params['user'] if params['user'].present?
        conditions[:changeable_type] = params['model'] if params['model'].present?
Severity: Minor
Found in app/models/fae/change.rb - About 3 hrs 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

Cyclomatic complexity for filter is too high. [17/6]
Open

      def filter(params)
        # build conditions if specific params are present
        conditions = {}
        conditions[:user_id] = params['user'] if params['user'].present?
        conditions[:changeable_type] = params['model'] if params['model'].present?
Severity: Minor
Found in app/models/fae/change.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.

Perceived complexity for filter is too high. [16/7]
Open

      def filter(params)
        # build conditions if specific params are present
        conditions = {}
        conditions[:user_id] = params['user'] if params['user'].present?
        conditions[:changeable_type] = params['model'] if params['model'].present?
Severity: Minor
Found in app/models/fae/change.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

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

      def filter(params)
        # build conditions if specific params are present
        conditions = {}
        conditions[:user_id] = params['user'] if params['user'].present?
        conditions[:changeable_type] = params['model'] if params['model'].present?
Severity: Minor
Found in app/models/fae/change.rb - About 1 hr to fix

    Indent when as deep as case.
    Open

              when 'last-week' then   ['fae_changes.updated_at >= ?', 1.week.ago]
    Severity: Minor
    Found in app/models/fae/change.rb by rubocop

    This cop checks how the whens of a case expression are indented in relation to its case or end keyword.

    It will register a separate offense for each misaligned when.

    Example:

    # If Layout/EndAlignment is set to keyword style (default)
    # *case* and *end* should always be aligned to same depth,
    # and therefore *when* should always be aligned to both -
    # regardless of configuration.
    
    # bad for all styles
    case n
      when 0
        x * 2
      else
        y / 3
    end
    
    # good for all styles
    case n
    when 0
      x * 2
    else
      y / 3
    end

    Example: EnforcedStyle: case (default)

    # if EndAlignment is set to other style such as
    # start_of_line (as shown below), then *when* alignment
    # configuration does have an effect.
    
    # bad
    a = case n
    when 0
      x * 2
    else
      y / 3
    end
    
    # good
    a = case n
        when 0
          x * 2
        else
          y / 3
    end

    Example: EnforcedStyle: end

    # bad
    a = case n
        when 0
          x * 2
        else
          y / 3
    end
    
    # good
    a = case n
    when 0
      x * 2
    else
      y / 3
    end

    Line is too long. [152/80]
    Open

              date_scope = ['fae_changes.updated_at >= ? AND fae_changes.updated_at <= ?', start_date, end_date] if start_date.present? && end_date.present?
    Severity: Minor
    Found in app/models/fae/change.rb by rubocop

    Line is too long. [99/80]
    Open

              end_date   = params['end_date'].present? ? CGI.unescape(params['end_date']).to_date : nil
    Severity: Minor
    Found in app/models/fae/change.rb by rubocop

    Line is too long. [89/80]
    Open

              date_scope = ['fae_changes.updated_at >= ?', start_date] if start_date.present?
    Severity: Minor
    Found in app/models/fae/change.rb by rubocop

    end at 50, 10 is not aligned with case at 43, 23.
    Open

              end
    Severity: Minor
    Found in app/models/fae/change.rb by rubocop

    This cop checks whether the end keywords are aligned properly.

    Three modes are supported through the EnforcedStyleAlignWith configuration parameter:

    If it's set to keyword (which is the default), the end shall be aligned with the start of the keyword (if, class, etc.).

    If it's set to variable the end shall be aligned with the left-hand-side of the variable assignment, if there is one.

    If it's set to start_of_line, the end shall be aligned with the start of the line where the matching keyword appears.

    Example: EnforcedStyleAlignWith: keyword (default)

    # bad
    
    variable = if true
        end
    
    # good
    
    variable = if true
               end

    Example: EnforcedStyleAlignWith: variable

    # bad
    
    variable = if true
        end
    
    # good
    
    variable = if true
    end

    Example: EnforcedStyleAlignWith: startofline

    # bad
    
    variable = if true
        end
    
    # good
    
    puts(if true
    end)

    Line is too long. [103/80]
    Open

              start_date = params['start_date'].present? ? CGI.unescape(params['start_date']).to_date : nil
    Severity: Minor
    Found in app/models/fae/change.rb by rubocop

    Extra empty line detected at class body end.
    Open

    
        end
    Severity: Minor
    Found in app/models/fae/change.rb by rubocop

    This cops checks if empty lines around the bodies of classes match the configuration.

    Example: EnforcedStyle: empty_lines

    # good
    
    class Foo
    
      def bar
        # ...
      end
    
    end

    Example: EnforcedStyle: emptylinesexcept_namespace

    # good
    
    class Foo
      class Bar
    
        # ...
    
      end
    end

    Example: EnforcedStyle: emptylinesspecial

    # good
    class Foo
    
      def bar; end
    
    end

    Example: EnforcedStyle: noemptylines (default)

    # good
    
    class Foo
      def bar
        # ...
      end
    end

    Line is too long. [85/80]
    Open

              date_scope = ['fae_changes.updated_at <= ?', end_date] if end_date.present?
    Severity: Minor
    Found in app/models/fae/change.rb by rubocop

    Line is too long. [81/80]
    Open

              when 'last-hour' then   ['fae_changes.updated_at >= ?', 60.minutes.ago]
    Severity: Minor
    Found in app/models/fae/change.rb by rubocop

    Indent when as deep as case.
    Open

              when 'last-day' then    ['fae_changes.updated_at >= ?', 1.day.ago]
    Severity: Minor
    Found in app/models/fae/change.rb by rubocop

    This cop checks how the whens of a case expression are indented in relation to its case or end keyword.

    It will register a separate offense for each misaligned when.

    Example:

    # If Layout/EndAlignment is set to keyword style (default)
    # *case* and *end* should always be aligned to same depth,
    # and therefore *when* should always be aligned to both -
    # regardless of configuration.
    
    # bad for all styles
    case n
      when 0
        x * 2
      else
        y / 3
    end
    
    # good for all styles
    case n
    when 0
      x * 2
    else
      y / 3
    end

    Example: EnforcedStyle: case (default)

    # if EndAlignment is set to other style such as
    # start_of_line (as shown below), then *when* alignment
    # configuration does have an effect.
    
    # bad
    a = case n
    when 0
      x * 2
    else
      y / 3
    end
    
    # good
    a = case n
        when 0
          x * 2
        else
          y / 3
    end

    Example: EnforcedStyle: end

    # bad
    a = case n
        when 0
          x * 2
        else
          y / 3
    end
    
    # good
    a = case n
    when 0
      x * 2
    else
      y / 3
    end

    Indent when as deep as case.
    Open

              when 'last-hour' then   ['fae_changes.updated_at >= ?', 60.minutes.ago]
    Severity: Minor
    Found in app/models/fae/change.rb by rubocop

    This cop checks how the whens of a case expression are indented in relation to its case or end keyword.

    It will register a separate offense for each misaligned when.

    Example:

    # If Layout/EndAlignment is set to keyword style (default)
    # *case* and *end* should always be aligned to same depth,
    # and therefore *when* should always be aligned to both -
    # regardless of configuration.
    
    # bad for all styles
    case n
      when 0
        x * 2
      else
        y / 3
    end
    
    # good for all styles
    case n
    when 0
      x * 2
    else
      y / 3
    end

    Example: EnforcedStyle: case (default)

    # if EndAlignment is set to other style such as
    # start_of_line (as shown below), then *when* alignment
    # configuration does have an effect.
    
    # bad
    a = case n
    when 0
      x * 2
    else
      y / 3
    end
    
    # good
    a = case n
        when 0
          x * 2
        else
          y / 3
    end

    Example: EnforcedStyle: end

    # bad
    a = case n
        when 0
          x * 2
        else
          y / 3
    end
    
    # good
    a = case n
    when 0
      x * 2
    else
      y / 3
    end

    Space missing after comma.
    Open

            pluck(:changeable_type).uniq.sort.map{ |changeable_type| [changeable_type.gsub('Fae::',''), changeable_type] }
    Severity: Minor
    Found in app/models/fae/change.rb by rubocop

    Checks for comma (,) not followed by some kind of space.

    Example:

    # bad
    [1,2]
    { foo:bar,}
    
    # good
    [1, 2]
    { foo:bar, }

    Extra empty line detected at class body beginning.
    Open

    
          # writing current_user to thread for thread safety
    Severity: Minor
    Found in app/models/fae/change.rb by rubocop

    This cops checks if empty lines around the bodies of classes match the configuration.

    Example: EnforcedStyle: empty_lines

    # good
    
    class Foo
    
      def bar
        # ...
      end
    
    end

    Example: EnforcedStyle: emptylinesexcept_namespace

    # good
    
    class Foo
      class Bar
    
        # ...
    
      end
    end

    Example: EnforcedStyle: emptylinesspecial

    # good
    class Foo
    
      def bar; end
    
    end

    Example: EnforcedStyle: noemptylines (default)

    # good
    
    class Foo
      def bar
        # ...
      end
    end

    Space missing to the left of {.
    Open

            pluck(:changeable_type).uniq.sort.map{ |changeable_type| [changeable_type.gsub('Fae::',''), changeable_type] }
    Severity: Minor
    Found in app/models/fae/change.rb by rubocop

    Checks that block braces have or don't have a space before the opening brace depending on configuration.

    Example:

    # bad
    foo.map{ |a|
      a.bar.to_s
    }
    
    # good
    foo.map { |a|
      a.bar.to_s
    }

    Line is too long. [118/80]
    Open

            pluck(:changeable_type).uniq.sort.map{ |changeable_type| [changeable_type.gsub('Fae::',''), changeable_type] }
    Severity: Minor
    Found in app/models/fae/change.rb by rubocop

    Missing top-level class documentation comment.
    Open

      class Change < ActiveRecord::Base
    Severity: Minor
    Found in app/models/fae/change.rb by rubocop

    This cop checks for missing top-level documentation of classes and modules. Classes with no body are exempt from the check and so are namespace modules - modules that have nothing in their bodies except classes, other modules, or constant definitions.

    The documentation requirement is annulled if the class or module has a "#:nodoc:" comment next to it. Likewise, "#:nodoc: all" does the same for all its children.

    Example:

    # bad
    class Person
      # ...
    end
    
    # good
    # Description/Explanation of Person class
    class Person
      # ...
    end

    Line is too long. [82/80]
    Open

            conditions[:changeable_type] = params['model'] if params['model'].present?
    Severity: Minor
    Found in app/models/fae/change.rb by rubocop

    Indent when as deep as case.
    Open

              when 'last-month' then  ['fae_changes.updated_at >= ?', 1.month.ago]
    Severity: Minor
    Found in app/models/fae/change.rb by rubocop

    This cop checks how the whens of a case expression are indented in relation to its case or end keyword.

    It will register a separate offense for each misaligned when.

    Example:

    # If Layout/EndAlignment is set to keyword style (default)
    # *case* and *end* should always be aligned to same depth,
    # and therefore *when* should always be aligned to both -
    # regardless of configuration.
    
    # bad for all styles
    case n
      when 0
        x * 2
      else
        y / 3
    end
    
    # good for all styles
    case n
    when 0
      x * 2
    else
      y / 3
    end

    Example: EnforcedStyle: case (default)

    # if EndAlignment is set to other style such as
    # start_of_line (as shown below), then *when* alignment
    # configuration does have an effect.
    
    # bad
    a = case n
    when 0
      x * 2
    else
      y / 3
    end
    
    # good
    a = case n
        when 0
          x * 2
        else
          y / 3
    end

    Example: EnforcedStyle: end

    # bad
    a = case n
        when 0
          x * 2
        else
          y / 3
    end
    
    # good
    a = case n
    when 0
      x * 2
    else
      y / 3
    end

    Line is too long. [318/80]
    Open

              search = ["fae_users.first_name LIKE ? OR fae_users.last_name LIKE ? OR fae_changes.updated_attributes LIKE ? OR fae_changes.changeable_type LIKE ? OR fae_changes.change_type LIKE ?", "%#{params['search']}%", "%#{params['search']}%", "%#{params['search']}%", "%#{params['search']}%", "%#{params['search']}%"]
    Severity: Minor
    Found in app/models/fae/change.rb by rubocop

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

              search = ["fae_users.first_name LIKE ? OR fae_users.last_name LIKE ? OR fae_changes.updated_attributes LIKE ? OR fae_changes.changeable_type LIKE ? OR fae_changes.change_type LIKE ?", "%#{params['search']}%", "%#{params['search']}%", "%#{params['search']}%", "%#{params['search']}%", "%#{params['search']}%"]
    Severity: Minor
    Found in app/models/fae/change.rb by rubocop

    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