cobudget/cobudget-api

View on GitHub

Showing 21 of 21 total issues

Class Bucket has 30 methods (exceeds 20 allowed). Consider refactoring.
Open

class Bucket < ActiveRecord::Base
  after_create :add_account_after_create
  has_many :contributions, -> { order("amount DESC") }, dependent: :destroy
  has_many :comments, dependent: :destroy
  belongs_to :group
Severity: Minor
Found in app/models/bucket.rb - About 3 hrs to fix

    Method check_csv_for_errors has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
    Open

      def self.check_csv_for_errors(csv:, group:)
        errors = []
        if csv.nil? || csv.empty?
          errors << "csv is empty"
        else
    Severity: Minor
    Found in app/services/allocation_service.rb - About 3 hrs 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

    Class RecentActivityService has 21 methods (exceeds 20 allowed). Consider refactoring.
    Open

    class RecentActivityService
      attr_accessor :comments_on_bucket_you_participated_in,
                    :comments_on_buckets_user_authored,
                    :contributions_to_live_buckets_user_authored,
                    :funded_buckets_user_authored,
    Severity: Minor
    Found in app/services/recent_activity_service.rb - About 2 hrs to fix

      Method merge_users has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

        def self.merge_users(user_to_kill:, user_to_keep:)
          if user_to_kill == user_to_keep 
            puts "nope" unless Rails.env.test?
            return
          end
      Severity: Minor
      Found in app/services/user_service.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 create has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

          def create
            field = (resource_params.keys.map(&:to_sym) & resource_class.authentication_keys).first
      
            @resource = nil
            if field
      Severity: Minor
      Found in app/controllers/overrides/sessions_controller.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 generate_recent_activity_for has 38 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def generate_recent_activity_for(membership:, current_time:, personal_activity_only: false)
            user = membership.member
            group = membership.group
      
            Allocation.create(user: user, group: group, amount: 20000)
      Severity: Minor
      Found in lib/mailer_previews/user_mailer_preview.rb - About 1 hr to fix

        Method generate_csv_upload_preview has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

          def self.generate_csv_upload_preview(csv:, group:)
            csv.group_by { |row| row[0].downcase }.map do |email, rows|
              allocation_amount = rows.sum { |row| row[1].to_f }
              notify = rows[0][2]
              notify = !!(if notify == 'false' || notify == ' false' then false else true end)
        Severity: Minor
        Found in app/services/allocation_service.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 create has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

          def create
            group = Group.find(allocation_params[:group_id])
            user = User.find(allocation_params[:user_id])
            amount = allocation_params[:amount]
            notify = allocation_params[:notify]
        Severity: Minor
        Found in app/controllers/allocations_controller.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 create has 30 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def create
              field = (resource_params.keys.map(&:to_sym) & resource_class.authentication_keys).first
        
              @resource = nil
              if field
        Severity: Minor
        Found in app/controllers/overrides/sessions_controller.rb - About 1 hr to fix

          Method create has 28 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def create
              group = Group.find(allocation_params[:group_id])
              user = User.find(allocation_params[:user_id])
              amount = allocation_params[:amount]
              notify = allocation_params[:notify]
          Severity: Minor
          Found in app/controllers/allocations_controller.rb - About 1 hr to fix

            Method check_csv_for_errors has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

              def self.check_csv_for_errors(csv: )
                errors = []
                if csv.nil? || csv.empty?
                  errors << "csv is empty"
                else
            Severity: Minor
            Found in app/services/membership_service.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 last_activity_at has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

              def last_activity_at
                last_bucket = buckets.order(updated_at: :desc).limit(1).first
                last_bucket_updated_at = last_bucket ? last_bucket.updated_at : nil
                last_membership = memberships.order(updated_at: :desc).limit(1).first
                last_membership_updated_at = last_membership ? last_membership.updated_at : nil
            Severity: Minor
            Found in app/models/group.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

            Consider simplifying this complex logical expression.
            Open

                render nothing: true, status: 403 and return unless ((current_user.is_member_of?(group) && bucket.user == current_user) || current_user.is_admin_for?(group)) && 
                  (bucket.is_idea? || bucket.is_funding? || bucket.is_funded?)
            Severity: Major
            Found in app/controllers/buckets_controller.rb - About 1 hr to fix

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

                def update_password
                  render status: 401, nothing: true and return unless valid_update_password_params?
                  render status: 401, json: { errors: ["current_password is incorrect"] } and return unless current_user.valid_password?(params[:current_password])
                  render status: 400, json: { errors: ["passwords do not match"] } and return unless params[:password] == params[:confirm_password]
                  current_user.update(password: params[:password])
              Severity: Minor
              Found in app/controllers/users_controller.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

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

                def create
                  user = User.find_by_email(params[:email].downcase) || User.create_with_confirmation_token(email: params[:email], name: params[:name])
                  render nothing: true, status: 400 and return unless user.valid?
                  if membership = Membership.find_by(member: user, group: group)
                    if membership.active?
              Severity: Minor
              Found in app/controllers/memberships_controller.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

              Method generate_csv_upload_preview has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

                def self.generate_csv_upload_preview(csv:, group:)
                  csv.uniq { |row| row[0] }.map do |row|
                    email = row[0].downcase
                    user = User.find_by_email(email)
                    {
              Severity: Minor
              Found in app/services/membership_service.rb - About 45 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

              Method authenticate_from_token! has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

                def authenticate_from_token!
                  # Set the authentication params if not already present
                  if user_token = params[:user_token].blank? && request.headers["X-User-Token"]
                    params[:user_token] = user_token
                  end
              Severity: Minor
              Found in app/controllers/concerns/token_authentication.rb - About 45 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

              Method collection_scoped_to_group has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

                  def collection_scoped_to_group(collection:, group:)
                    return nil unless collection && collection.any?
                    scoped_collection =
                      if collection.table_name == "comments" || collection.table_name == "contributions"
                        collection.joins(:bucket).where(buckets: {group_id: group.id})
              Severity: Minor
              Found in app/services/recent_activity_service.rb - About 45 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

              Method archive has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                def self.archive(bucket, user, exclude_author_from_email_notifications: false)
                  ActiveRecord::Base.transaction do
                    if bucket.is_idea? || bucket.is_funding? || bucket.is_funded?
                      bucket.contributors(exclude_author: exclude_author_from_email_notifications).each do |funder|
                        # Don't notify archived members
              Severity: Minor
              Found in app/services/bucket_service.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

              Method update has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                def update
                  bucket = Bucket.with_totals.find(params[:id])
                  render status: 403, nothing: true and return unless bucket.is_editable_by?(current_user) && 
                    (bucket.is_idea? || bucket.is_funding? || bucket.is_funded?)
                  bucket.update_attributes(bucket_params_update)
              Severity: Minor
              Found in app/controllers/buckets_controller.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

              Severity
              Category
              Status
              Source
              Language