MidnightRiders/MemberPortal

View on GitHub
app/models/relative.rb

Summary

Maintainability
A
0 mins
Test Coverage

Mass assignment is not restricted using attr_accessible
Open

class Relative < Membership
Severity: Critical
Found in app/models/relative.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 notify_slack is too high. [<0, 22, 0> 22/17] (http://c2.com/cgi/wiki?AbcMetric, https://en.wikipedia.org/wiki/ABC_Software_Metric)
Open

  def notify_slack
    SlackBot.post_message("#{user.first_name} #{user.last_name} (<#{url_helpers.user_url(user)}|@#{user.username}>) has accepted *#{family.user.first_name} #{family.user.last_name}’s Family Membership invitation*:\nThere are now *#{Membership.for_year(year).size} registered #{year} Memberships.*\n#{Membership.breakdown(year)}", 'membership')
  end
Severity: Minor
Found in app/models/relative.rb by rubocop

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.

Interpreting ABC size:

  • <= 17 satisfactory
  • 18..30 unsatisfactory
  • > 30 dangerous

You can have repeated "attributes" calls count as a single "branch". For this purpose, attributes are any method with no argument; no attempt is meant to distinguish actual attr_reader from other methods.

Example: CountRepeatedAttributes: false (default is true)

# `model` and `current_user`, referenced 3 times each,
 # are each counted as only 1 branch each if
 # `CountRepeatedAttributes` is set to 'false'

 def search
   @posts = model.active.visible_by(current_user)
             .search(params[:q])
   @posts = model.some_process(@posts, current_user)
   @posts = model.another_process(@posts, current_user)

   render 'pages/search/page'
 end

This cop also takes into account AllowedMethods (defaults to []) And AllowedPatterns (defaults to [])

Line is too long. [343/140] (https://rubystyle.guide#max-line-length)
Open

    SlackBot.post_message("#{user.first_name} #{user.last_name} (<#{url_helpers.user_url(user)}|@#{user.username}>) has accepted *#{family.user.first_name} #{family.user.last_name}’s Family Membership invitation*:\nThere are now *#{Membership.for_year(year).size} registered #{year} Memberships.*\n#{Membership.breakdown(year)}", 'membership')
Severity: Minor
Found in app/models/relative.rb by rubocop

Checks the length of lines in the source code. The maximum length is configurable. The tab size is configured in the IndentationWidth of the Layout/IndentationStyle cop. It also ignores a shebang line by default.

This cop has some autocorrection capabilities. It can programmatically shorten certain long lines by inserting line breaks into expressions that can be safely split across lines. These include arrays, hashes, and method calls with argument lists.

If autocorrection is enabled, the following Layout cops are recommended to further format the broken lines. (Many of these are enabled by default.)

  • ArgumentAlignment
  • ArrayAlignment
  • BlockAlignment
  • BlockDelimiters
  • BlockEndNewline
  • ClosingParenthesisIndentation
  • FirstArgumentIndentation
  • FirstArrayElementIndentation
  • FirstHashElementIndentation
  • FirstParameterIndentation
  • HashAlignment
  • IndentationWidth
  • MultilineArrayLineBreaks
  • MultilineBlockLayout
  • MultilineHashBraceLayout
  • MultilineHashKeyLineBreaks
  • MultilineMethodArgumentLineBreaks
  • MultilineMethodParameterLineBreaks
  • ParameterAlignment

Together, these cops will pretty print hashes, arrays, method calls, etc. For example, let's say the max columns is 25:

Example:

# bad
{foo: "0000000000", bar: "0000000000", baz: "0000000000"}

# good
{foo: "0000000000",
bar: "0000000000", baz: "0000000000"}

# good (with recommended cops enabled)
{
  foo: "0000000000",
  bar: "0000000000",
  baz: "0000000000",
}

Use info[:invited_email] instead of info.dig(:invited_email).
Open

    info.dig(:invited_email)&.strip!
Severity: Minor
Found in app/models/relative.rb by rubocop

Sometimes using dig method ends up with just a single argument. In such cases, dig should be replaced with [].

Safety:

This cop is unsafe because it cannot be guaranteed that the receiver is an Enumerable or does not have a nonstandard implementation of dig.

Example:

# bad
{ key: 'value' }.dig(:key)
[1, 2, 3].dig(0)

# good
{ key: 'value' }[:key]
[1, 2, 3][0]

# good
{ key1: { key2: 'value' } }.dig(:key1, :key2)
[1, [2, [3]]].dig(1, 1)

# good
keys = %i[key1 key2]
{ key1: { key2: 'value' } }.dig(*keys)

Rename has_good_family to good_family?. (https://rubystyle.guide#bool-methods-qmark)
Open

  def has_good_family
Severity: Minor
Found in app/models/relative.rb by rubocop

Checks that predicate methods names end with a question mark and do not start with a forbidden prefix.

A method is determined to be a predicate method if its name starts with one of the prefixes defined in the NamePrefix configuration. You can change what prefixes are considered by changing this option. Any method name that starts with one of these prefixes is required by the cop to end with a ?. Other methods can be allowed by adding to the AllowedMethods configuration.

NOTE: The is_a? method is allowed by default.

If ForbiddenPrefixes is set, methods that start with the configured prefixes will not be allowed and will be removed by autocorrection.

In other words, if ForbiddenPrefixes is empty, a method named is_foo will register an offense only due to the lack of question mark (and will be autocorrected to is_foo?). If ForbiddenPrefixes contains is_, is_foo will register an offense both because the ? is missing and because of the is_ prefix, and will be corrected to foo?.

NOTE: ForbiddenPrefixes is only applied to prefixes in NamePrefix; a prefix in the former but not the latter will not be considered by this cop.

Example:

# bad
def is_even(value)
end

def is_even?(value)
end

# good
def even?(value)
end

# bad
def has_value
end

def has_value?
end

# good
def value?
end

Example: AllowedMethods: ['is_a?'] (default)

# good
def is_a?(value)
end

Use e instead of invalid.
Open

  rescue ActiveRecord::RecordInvalid => invalid
Severity: Minor
Found in app/models/relative.rb by rubocop

Makes sure that rescued exceptions variables are named as expected.

The PreferredName config option takes a String. It represents the required name of the variable. Its default is e.

NOTE: This cop does not consider nested rescues because it cannot guarantee that the variable from the outer rescue is not used within the inner rescue (in which case, changing the inner variable would shadow the outer variable).

Example: PreferredName: e (default)

# bad
begin
  # do something
rescue MyException => exception
  # do something
end

# good
begin
  # do something
rescue MyException => e
  # do something
end

# good
begin
  # do something
rescue MyException => _e
  # do something
end

Example: PreferredName: exception

# bad
begin
  # do something
rescue MyException => e
  # do something
end

# good
begin
  # do something
rescue MyException => exception
  # do something
end

# good
begin
  # do something
rescue MyException => _exception
  # do something
end

There are no issues that match your filters.

Category
Status