app/models/spending_proposal.rb
Method reason_for_not_being_votable_by
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
Open
def reason_for_not_being_votable_by(user)
return :not_voting_allowed if Setting["feature.spending_proposal_features.voting_allowed"].blank?
return :not_logged_in unless user
return :not_verified unless user.can?(:vote, SpendingProposal)
return :unfeasible if unfeasible?
- Read upRead up
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
Avoid too many return
statements within this method. Open
Open
return :organization if user.organization?
Line is too long. [132/100] (https://github.com/bbatsov/ruby-style-guide#80-character-limits) Open
Open
scope :managed, -> { valuation_open.where(valuation_assignments_count: 0).where("administrator_id IS NOT ?", nil) }
- Exclude checks
Line is too long. [103/100] (https://github.com/bbatsov/ruby-style-guide#80-character-limits) Open
Open
results = results.by_admin(params[:administrator_id]) if params[:administrator_id].present?
- Exclude checks
Line is too long. [129/100] (https://github.com/bbatsov/ruby-style-guide#80-character-limits) Open
Open
scope :valuating, -> { valuation_open.where("valuation_assignments_count > 0 AND valuation_finished = ?", false) }
- Exclude checks
Line is too long. [134/100] (https://github.com/bbatsov/ruby-style-guide#80-character-limits) Open
Open
scope :by_valuator, ->(valuator) { where("valuation_assignments.valuator_id = ?", valuator.presence).joins(:valuation_assignments) }
- Exclude checks
Line is too long. [101/100] (https://github.com/bbatsov/ruby-style-guide#80-character-limits) Open
Open
return :not_voting_allowed if Setting["feature.spending_proposal_features.voting_allowed"].blank?
- Exclude checks
%w
-literals should be delimited by [
and ]
. (https://github.com/bbatsov/ruby-style-guide#percent-literal-braces) Open
Open
params.select{|x, _| %w{geozone_id administrator_id tag_name valuator_id}.include? x.to_s }
- Read upRead up
- Exclude checks
This cop enforces the consistent usage of %
-literal delimiters.
Specify the 'default' key to set all preferred delimiters at once. You can continue to specify individual preferred delimiters to override the default.
Example:
# Style/PercentLiteralDelimiters:
# PreferredDelimiters:
# default: '[]'
# '%i': '()'
# good
%w[alpha beta] + %i(gamma delta)
# bad
%W(alpha #{beta})
# bad
%I(alpha beta)