tsurupin/portfolio

View on GitHub
app/models/post/form.rb

Summary

Maintainability
A
35 mins
Test Coverage

Assignment Branch Condition size for save_from_associations is too high. [32.28/20]
Open

  def save_from_associations(params)
    ActiveRecord::Base.transaction do
      delete_unnecessary_items!(params[ITEMS_ATTRIBUTES]) if id
      delete_unnecessary_tags!(params[TAGGINGS_ATTRIBUTES]) if id

Severity: Minor
Found in app/models/post/form.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. [22/15]
Open

  def save_from_associations(params)
    ActiveRecord::Base.transaction do
      delete_unnecessary_items!(params[ITEMS_ATTRIBUTES]) if id
      delete_unnecessary_tags!(params[TAGGINGS_ATTRIBUTES]) if id

Severity: Minor
Found in app/models/post/form.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 save_from_associations has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  def save_from_associations(params)
    ActiveRecord::Base.transaction do
      delete_unnecessary_items!(params[ITEMS_ATTRIBUTES]) if id
      delete_unnecessary_tags!(params[TAGGINGS_ATTRIBUTES]) if id

Severity: Minor
Found in app/models/post/form.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

Extra empty line detected before the rescue.
Open


  rescue => e
Severity: Minor
Found in app/models/post/form.rb by rubocop

This cops checks if empty lines exist around the bodies of begin sections. This cop doesn't check empty lines at begin body beginning/end and around method definition body. Style/EmptyLinesAroundBeginBody or Style/EmptyLinesAroundMethodBody can be used for this purpose.

Example:

# good

begin
  do_something
rescue
  do_something2
else
  do_something3
ensure
  do_something4
end

# good

def foo
  do_something
rescue
  do_something2
end

# bad

begin
  do_something

rescue

  do_something2

else

  do_something3

ensure

  do_something4
end

# bad

def foo
  do_something

rescue

  do_something2
end

Do not freeze immutable objects, as freezing them has no effect.
Open

  ITEMS_ATTRIBUTES = 'items_attributes'.freeze
Severity: Minor
Found in app/models/post/form.rb by rubocop

This cop check for uses of Object#freeze on immutable objects.

Example:

# bad
CONST = 1.freeze

# good
CONST = 1

Avoid rescuing without specifying an error class.
Open

  rescue => e
Severity: Minor
Found in app/models/post/form.rb by rubocop

This cop checks for rescuing StandardError. There are two supported styles implicit and explicit. This cop will not register an offense if any error other than StandardError is specified.

Example: EnforcedStyle: implicit

# `implicit` will enforce using `rescue` instead of
# `rescue StandardError`.

# bad
begin
  foo
rescue StandardError
  bar
end

# good
begin
  foo
rescue
  bar
end

# good
begin
  foo
rescue OtherError
  bar
end

# good
begin
  foo
rescue StandardError, SecurityError
  bar
end

Example: EnforcedStyle: explicit (default)

# `explicit` will enforce using `rescue StandardError`
# instead of `rescue`.

# bad
begin
  foo
rescue
  bar
end

# good
begin
  foo
rescue StandardError
  bar
end

# good
begin
  foo
rescue OtherError
  bar
end

# good
begin
  foo
rescue StandardError, SecurityError
  bar
end

Use %i or %I for an array of symbols.
Open

    items_attributes: [:id, :sort_rank, :target_id, :target_type, :description, :image, :caption, :twitter_id],
Severity: Minor
Found in app/models/post/form.rb by rubocop

This cop can check for array literals made up of symbols that are not using the %i() syntax.

Alternatively, it checks for symbol arrays using the %i() syntax on projects which do not want to use that syntax.

Configuration option: MinSize If set, arrays with fewer elements than this value will not trigger the cop. For example, a MinSize of3` will not enforce a style on an array of 2 or fewer elements.

Example: EnforcedStyle: percent (default)

# good
%i[foo bar baz]

# bad
[:foo, :bar, :baz]

Example: EnforcedStyle: brackets

# good
[:foo, :bar, :baz]

# bad
%i[foo bar baz]

Add an empty line after magic comments.
Open

# == Schema Information
Severity: Minor
Found in app/models/post/form.rb by rubocop

Checks for a newline after the final magic comment.

Example:

# good
# frozen_string_literal: true

# Some documentation for Person
class Person
  # Some code
end

# bad
# frozen_string_literal: true
# Some documentation for Person
class Person
  # Some code
end

Use %i or %I for an array of symbols.
Open

    taggings_attributes: [:id, :text]
Severity: Minor
Found in app/models/post/form.rb by rubocop

This cop can check for array literals made up of symbols that are not using the %i() syntax.

Alternatively, it checks for symbol arrays using the %i() syntax on projects which do not want to use that syntax.

Configuration option: MinSize If set, arrays with fewer elements than this value will not trigger the cop. For example, a MinSize of3` will not enforce a style on an array of 2 or fewer elements.

Example: EnforcedStyle: percent (default)

# good
%i[foo bar baz]

# bad
[:foo, :bar, :baz]

Example: EnforcedStyle: brackets

# good
[:foo, :bar, :baz]

# bad
%i[foo bar baz]

Do not chain ordinary method call after safe navigation operator.
Open

      params[ITEMS_ATTRIBUTES]&.each.with_index(1) do |item, index|
Severity: Minor
Found in app/models/post/form.rb by rubocop

The safe navigation operator returns nil if the receiver is nil. If you chain an ordinary method call after a safe navigation operator, it raises NoMethodError. We should use a safe navigation operator after a safe navigation operator. This cop checks for the problem outlined above.

Example:

# bad

x&.foo.bar
x&.foo + bar
x&.foo[bar]

Example:

# good

x&.foo&.bar
x&.foo || bar

Do not freeze immutable objects, as freezing them has no effect.
Open

  TAGGINGS_ATTRIBUTES = 'taggings_attributes'.freeze
Severity: Minor
Found in app/models/post/form.rb by rubocop

This cop check for uses of Object#freeze on immutable objects.

Example:

# bad
CONST = 1.freeze

# good
CONST = 1

There are no issues that match your filters.

Category
Status