app/models/budget/investment.rb

Summary

Maintainability
C
1 day
Test Coverage

Class Investment has 47 methods (exceeds 20 allowed). Consider refactoring.
Open

  class Investment < ActiveRecord::Base
    SORTING_OPTIONS = %w(id title supports).freeze

    include Rails.application.routes.url_helpers
    include Measurable
Severity: Minor
Found in app/models/budget/investment.rb - About 6 hrs to fix

    File investment.rb has 285 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    class Budget
      class Investment < ActiveRecord::Base
        SORTING_OPTIONS = %w(id title supports).freeze
    
        include Rails.application.routes.url_helpers
    Severity: Minor
    Found in app/models/budget/investment.rb - About 2 hrs to fix

      Method scoped_filter has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

          def self.scoped_filter(params, current_filter)
            budget  = Budget.find_by(slug: params[:budget_id]) || Budget.find_by(id: params[:budget_id])
            results = Investment.by_budget(budget)
      
            results = results.where("cached_votes_up + physical_votes >= ?",
      Severity: Minor
      Found in app/models/budget/investment.rb - About 1 hr 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

      Method reason_for_not_being_ballotable_by has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

          def reason_for_not_being_ballotable_by(user, ballot)
            return permission_problem(user)         if permission_problem?(user)
            return :not_selected                    unless selected?
            return :no_ballots_allowed              unless budget.balloting?
            return :different_heading_assigned_html unless ballot.valid_heading?(heading)
      Severity: Minor
      Found in app/models/budget/investment.rb - About 55 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 :not_enough_money_html           if ballot.present? && !enough_money?(ballot)
      Severity: Major
      Found in app/models/budget/investment.rb - About 30 mins to fix

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

              results = results.by_valuator_group(params[:valuator_group_id])      if params[:valuator_group_id].present?
        Severity: Minor
        Found in app/models/budget/investment.rb by rubocop

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

            scope :valuation_finished_feasible, -> { where(valuation_finished: true, feasibility: "feasible") }
        Severity: Minor
        Found in app/models/budget/investment.rb by rubocop

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

              results = results.by_heading(params[:heading_id])                    if params[:heading_id].present?
        Severity: Minor
        Found in app/models/budget/investment.rb by rubocop

        Line is too long. [112/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/budget/investment.rb by rubocop

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

            SORTING_OPTIONS = %w(id title supports).freeze
        Severity: Minor
        Found in app/models/budget/investment.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)

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

              results = advanced_filters(params, results)                          if params[:advanced_filters].present?
        Severity: Minor
        Found in app/models/budget/investment.rb by rubocop

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

            scope :sort_by_price,            -> { reorder(price: :desc, confidence_score: :desc, id: :desc) }
        Severity: Minor
        Found in app/models/budget/investment.rb by rubocop

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

            scope :by_valuator,       ->(valuator_id) { where("budget_valuator_assignments.valuator_id = ?", valuator_id).joins(:valuator_assignments) }
        Severity: Minor
        Found in app/models/budget/investment.rb by rubocop

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

            scope :valuating,                   -> { valuation_open.where("valuator_assignments_count > 0 OR valuator_group_assignments_count > 0" ) }
        Severity: Minor
        Found in app/models/budget/investment.rb by rubocop

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

              results = results.by_tag(params[:tag_name])                          if params[:tag_name].present?
        Severity: Minor
        Found in app/models/budget/investment.rb by rubocop

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

              user.votes.for_budget_investments(budget.investments.where(group: group)).votables.map(&:heading_id).uniq
        Severity: Minor
        Found in app/models/budget/investment.rb by rubocop

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

            scope :by_valuator_group, ->(valuator_group_id) { where("budget_valuator_group_assignments.valuator_group_id = ?", valuator_group_id).joins(:valuator_group_assignments) }
        Severity: Minor
        Found in app/models/budget/investment.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{heading_id group_id administrator_id tag_name valuator_id}.include?(x.to_s) }
        Severity: Minor
        Found in app/models/budget/investment.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)

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

              params.select{ |x, _| %w{heading_id group_id administrator_id tag_name valuator_id}.include?(x.to_s) }
        Severity: Minor
        Found in app/models/budget/investment.rb by rubocop

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

              results = results.where(group_id: params[:group_id])                 if params[:group_id].present?
        Severity: Minor
        Found in app/models/budget/investment.rb by rubocop

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

              ids += results.undecided.pluck(:id)                   if params[:advanced_filters].include?('undecided')
        Severity: Minor
        Found in app/models/budget/investment.rb by rubocop

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

              investments = investments.filter(params[:advanced_search]) if params[:advanced_search].present?
        Severity: Minor
        Found in app/models/budget/investment.rb by rubocop

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

              ids += results.valuation_finished_feasible.pluck(:id) if params[:advanced_filters].include?('feasible')
        Severity: Minor
        Found in app/models/budget/investment.rb by rubocop

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

                ids += Investment.where(heading_id: hid).order(confidence_score: :desc).limit(max_per_heading).pluck(:id)
        Severity: Minor
        Found in app/models/budget/investment.rb by rubocop

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

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

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

            scope :under_valuation,             -> { valuation_open.valuating.where("administrator_id IS NOT ?", nil) }
        Severity: Minor
        Found in app/models/budget/investment.rb by rubocop

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

                                      params[:min_total_supports])                    if params[:min_total_supports].present?
        Severity: Minor
        Found in app/models/budget/investment.rb by rubocop

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

              ids += results.where(selected: true).pluck(:id)       if params[:advanced_filters].include?('selected')
        Severity: Minor
        Found in app/models/budget/investment.rb by rubocop

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

            scope :sort_by_random,           ->(seed) { reorder("budget_investments.id % #{seed.to_f.nonzero? ? seed.to_f : 1}, budget_investments.id") }
        Severity: Minor
        Found in app/models/budget/investment.rb by rubocop

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

              results = results.by_valuator(params[:valuator_id])                  if params[:valuator_id].present?
        Severity: Minor
        Found in app/models/budget/investment.rb by rubocop

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

              ids += results.unfeasible.pluck(:id)                  if params[:advanced_filters].include?('unfeasible')
        Severity: Minor
        Found in app/models/budget/investment.rb by rubocop

        There are no issues that match your filters.

        Category
        Status