Assignment Branch Condition size for response_flow_from_email is too high. [<2, 21, 4> 21.47/17] Open
def response_flow_from_email
sign_in user
reset_time_period_index
result = ResponseFlowFromEmail.new(params, @user).call
if params[:time_period_id] == TimePeriod.current.id.to_s
- Read upRead up
- Exclude checks
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`, refenced 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 IgnoredMethods
(defaults to []
)
Memoized variable @response
does not match method name retrieve_response
. Use @retrieve_response
instead. Open
@response ||= Response.find_by(id: params[:id])
- Read upRead up
- Exclude checks
Checks for memoized methods whose instance variable name
does not match the method name. Applies to both regular methods
(defined with def
) and dynamic methods (defined with
define_method
or define_singleton_method
).
This cop can be configured with the EnforcedStyleForLeadingUnderscores directive. It can be configured to allow for memoized instance variables prefixed with an underscore. Prefixing ivars with an underscore is a convention that is used to implicitly indicate that an ivar should not be set or referenced outside of the memoization method.
Safety:
This cop relies on the pattern @instance_var ||= ...
,
but this is sometimes used for other purposes than memoization
so this cop is considered unsafe.
Example: EnforcedStyleForLeadingUnderscores: disallowed (default)
# bad
# Method foo is memoized using an instance variable that is
# not `@foo`. This can cause confusion and bugs.
def foo
@something ||= calculate_expensive_thing
end
def foo
return @something if defined?(@something)
@something = calculate_expensive_thing
end
# good
def _foo
@foo ||= calculate_expensive_thing
end
# good
def foo
@foo ||= calculate_expensive_thing
end
# good
def foo
@foo ||= begin
calculate_expensive_thing
end
end
# good
def foo
helper_variable = something_we_need_to_calculate_foo
@foo ||= calculate_expensive_thing(helper_variable)
end
# good
define_method(:foo) do
@foo ||= calculate_expensive_thing
end
# good
define_method(:foo) do
return @foo if defined?(@foo)
@foo = calculate_expensive_thing
end
Example: EnforcedStyleForLeadingUnderscores: required
# bad
def foo
@something ||= calculate_expensive_thing
end
# bad
def foo
@foo ||= calculate_expensive_thing
end
def foo
return @foo if defined?(@foo)
@foo = calculate_expensive_thing
end
# good
def foo
@_foo ||= calculate_expensive_thing
end
# good
def _foo
@_foo ||= calculate_expensive_thing
end
def foo
return @_foo if defined?(@_foo)
@_foo = calculate_expensive_thing
end
# good
define_method(:foo) do
@_foo ||= calculate_expensive_thing
end
# good
define_method(:foo) do
return @_foo if defined?(@_foo)
@_foo = calculate_expensive_thing
end
Example: EnforcedStyleForLeadingUnderscores :optional
# bad
def foo
@something ||= calculate_expensive_thing
end
# good
def foo
@foo ||= calculate_expensive_thing
end
# good
def foo
@_foo ||= calculate_expensive_thing
end
# good
def _foo
@_foo ||= calculate_expensive_thing
end
# good
def foo
return @_foo if defined?(@_foo)
@_foo = calculate_expensive_thing
end
# good
define_method(:foo) do
@foo ||= calculate_expensive_thing
end
# good
define_method(:foo) do
@_foo ||= calculate_expensive_thing
end