armandofox/audience1st

View on GitHub
app/models/order.rb

Summary

Maintainability
F
3 days
Test Coverage
A
90%

Class Order has 54 methods (exceeds 20 allowed). Consider refactoring.
Open

class Order < ActiveRecord::Base
  belongs_to :customer
  belongs_to :purchaser, :class_name => 'Customer'
  belongs_to :processed_by, :class_name => 'Customer'
  has_many :items, :autosave => true, :dependent => :destroy
Severity: Major
Found in app/models/order.rb - About 7 hrs to fix

    File order.rb has 375 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    class Order < ActiveRecord::Base
      belongs_to :customer
      belongs_to :purchaser, :class_name => 'Customer'
      belongs_to :processed_by, :class_name => 'Customer'
      has_many :items, :autosave => true, :dependent => :destroy
    Severity: Minor
    Found in app/models/order.rb - About 5 hrs to fix

      Method add_tickets_from_params has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
      Open

        def add_tickets_from_params(valid_voucher_params, customer, promo_code: '', seats: [])
          return unless valid_voucher_params
          seats2 = seats.dup
          total_tickets = valid_voucher_params.map do |id,count|
            ValidVoucher.find(id).vouchertype.reservable? ? count.to_i  : 0
      Severity: Minor
      Found in app/models/order.rb - About 2 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

      Method check_purchaser_info has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
      Open

        def check_purchaser_info
          # walkup orders only need purchaser & recipient info to point to walkup
          #  customer, but regular orders need full purchaser & recipient info.
          if walkup?
            errors.add(:base, "Walkup order requires purchaser & recipient to be walkup customer") unless
      Severity: Minor
      Found in app/models/order.rb - About 2 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

      Method add_tickets_without_capacity_checks has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
      Open

        def add_tickets_without_capacity_checks(valid_voucher, number, seats=[])
          raise Order::NotPersistedError unless persisted?
          new_vouchers = VoucherInstantiator.new(valid_voucher.vouchertype, :promo_code => valid_voucher.supplied_promo_code || valid_voucher.promo_code).from_vouchertype(number)
          # reserve only if a specific showdate is indicated.  it seems like this method
          # should really take a vouchertype and showdate.
      Severity: Minor
      Found in app/models/order.rb - About 2 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

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

        def finalize!(sold_on_date = Time.current)
          raise Order::NotReadyError unless ready_for_purchase?
          # for credit card orders ONLY:
          #  mark order as Pending, run the card and rescue any errors, then finalize order.
          auth = nil
      Severity: Minor
      Found in app/models/order.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 ready_for_purchase? has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

        def ready_for_purchase?
          errors.clear
          errors.add(:base, 'Shopping cart is empty') if cart_empty?
          errors.add(:base, "You must specify the enrollee's name for classes") if
            includes_enrollment? && comments.blank?
      Severity: Minor
      Found in app/models/order.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 finalize! has 37 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def finalize!(sold_on_date = Time.current)
          raise Order::NotReadyError unless ready_for_purchase?
          # for credit card orders ONLY:
          #  mark order as Pending, run the card and rescue any errors, then finalize order.
          auth = nil
      Severity: Minor
      Found in app/models/order.rb - About 1 hr to fix

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

          def walkup_confirmation_notice
            notice = []
            notice << "#{'$%.02f' % donation.amount} donation" if includes_donation?
            if includes_vouchers?
              notice << "#{ticket_count} ticket" + (ticket_count > 1 ? 's' : '')
        Severity: Minor
        Found in app/models/order.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

        BUG found
        Open

            # :BUG: 79120088: this should be replaceable by
        Severity: Minor
        Found in app/models/order.rb by fixme

        unexpected token kRESCUE (Using Ruby 2.1 parser; configure using TargetRubyVersion parameter, under AllCops)
        Open

                rescue ActiveRecord::RecordInvalid, Voucher::ReservationError #  reservation couldn't be processed
        Severity: Minor
        Found in app/models/order.rb by rubocop

        dynamic constant assignment (Using Ruby 2.1 parser; configure using TargetRubyVersion parameter, under AllCops)
        Open

                rescue ActiveRecord::RecordInvalid, Voucher::ReservationError #  reservation couldn't be processed
        Severity: Minor
        Found in app/models/order.rb by rubocop

        There are no issues that match your filters.

        Category
        Status