Assignment Branch Condition size for call is too high. [<6, 20, 3> 21.1/17] Open
def call(*)
Visit.new(visit_properties) do |v|
v.started_at = attributes.fetch(:started_at) { Faker::Date.between(from: 2.years.ago, to: Date.today) }
v.user = attributes.fetch(:user) { Faker::Boolean.boolean ? User.generate : nil }
v.user_agent = Faker::Internet.user_agent
- 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`, 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 []
)
Do not use Date.today
without zone. Use Time.zone.today
instead. Open
v.started_at = attributes.fetch(:started_at) { Faker::Date.between(from: 2.years.ago, to: Date.today) }
- Read upRead up
- Exclude checks
This cop checks for the correct use of Date methods, such as Date.today, Date.current etc.
Using Date.today
is dangerous, because it doesn't know anything about
Rails time zone. You must use Time.zone.today
instead.
The cop also reports warnings when you are using to_time
method,
because it doesn't know about Rails time zone either.
Two styles are supported for this cop. When EnforcedStyle is 'strict'
then the Date methods today
, current
, yesterday
, and tomorrow
are prohibited and the usage of both to_time
and 'totimeincurrentzone' are reported as warning.
When EnforcedStyle is 'flexible' then only Date.today
is prohibited
and only to_time
is reported as warning.
Example: EnforcedStyle: strict
# bad
Date.current
Date.yesterday
Date.today
date.to_time
# good
Time.zone.today
Time.zone.today - 1.day
Example: EnforcedStyle: flexible (default)
# bad
Date.today
date.to_time
# good
Time.zone.today
Time.zone.today - 1.day
Date.current
Date.yesterday
date.in_time_zone