app/models/spending_proposal.rb

Summary

Maintainability
A
1 hr
Test Coverage

Method reason_for_not_being_votable_by has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
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?
Severity: Minor
Found in app/models/spending_proposal.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

Avoid too many return statements within this method.
Open

    return :organization  if user.organization?
Severity: Major
Found in app/models/spending_proposal.rb - About 30 mins to fix

    Line is too long. [132/100] (https://github.com/bbatsov/ruby-style-guide#80-character-limits)
    Open

      scope :managed,                -> { valuation_open.where(valuation_assignments_count: 0).where("administrator_id IS NOT ?", nil) }
    Severity: Minor
    Found in app/models/spending_proposal.rb by rubocop

    Line is too long. [103/100] (https://github.com/bbatsov/ruby-style-guide#80-character-limits)
    Open

        results = results.by_admin(params[:administrator_id])         if params[:administrator_id].present?
    Severity: Minor
    Found in app/models/spending_proposal.rb by rubocop

    Line is too long. [129/100] (https://github.com/bbatsov/ruby-style-guide#80-character-limits)
    Open

      scope :valuating,              -> { valuation_open.where("valuation_assignments_count > 0 AND valuation_finished = ?", false) }
    Severity: Minor
    Found in app/models/spending_proposal.rb by rubocop

    Line is too long. [134/100] (https://github.com/bbatsov/ruby-style-guide#80-character-limits)
    Open

      scope :by_valuator, ->(valuator) { where("valuation_assignments.valuator_id = ?", valuator.presence).joins(:valuation_assignments) }
    Severity: Minor
    Found in app/models/spending_proposal.rb by rubocop

    Line is too long. [101/100] (https://github.com/bbatsov/ruby-style-guide#80-character-limits)
    Open

        return :not_voting_allowed if Setting["feature.spending_proposal_features.voting_allowed"].blank?
    Severity: Minor
    Found in app/models/spending_proposal.rb by rubocop

    %w-literals should be delimited by [ and ]. (https://github.com/bbatsov/ruby-style-guide#percent-literal-braces)
    Open

        params.select{|x, _| %w{geozone_id administrator_id tag_name valuator_id}.include? x.to_s }
    Severity: Minor
    Found in app/models/spending_proposal.rb by rubocop

    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)

    There are no issues that match your filters.

    Category
    Status