app/controllers/pick_ems_controller.rb
Assignment Branch Condition size for vote is too high. [<1, 16, 6> 17.12/17] (http://c2.com/cgi/wiki?AbcMetric, https://en.wikipedia.org/wiki/ABC_Software_Metric) Open
Open
def vote
@pick_em = @match.pick_ems.find_or_initialize_by(user_id: current_user.id)
head :not_modified and return if @pick_em.result == pick_em_params[:result]&.to_i
if @pick_em.update(result: pick_em_params[:result])
render json: { result: @pick_em.result_key }, status: :accepted
- 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 []
)
Add empty line after guard clause. Open
Open
head :not_modified and return if @pick_em.result == pick_em_params[:result]&.to_i
- Read upRead up
- Exclude checks
Enforces empty line after guard clause
Example:
# bad
def foo
return if need_return?
bar
end
# good
def foo
return if need_return?
bar
end
# good
def foo
return if something?
return if something_different?
bar
end
# also good
def foo
if something?
do_something
return if need_return?
end
end