| Conditions | 18 |
| Total Lines | 88 |
| Lines | 34 |
| Ratio | 38.64 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
Complex classes like Response.transaction() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
| 1 | module AuthorizeNet::Reporting |
||
| 73 | def transaction |
||
| 74 | unless @transaction.nil? |
||
| 75 | transaction = build_entity(@transaction, Fields::TRANSACTION_DETAILS_ENTITY_DESCRIPTION) |
||
| 76 | |||
| 77 | ip = node_content_unless_nil(@transaction.at_css('customerIP')) |
||
| 78 | unless ip.nil? |
||
| 79 | transaction.customer ||= AuthorizeNet::CIM::CustomerProfile.new() |
||
| 80 | transaction.customer.ip = ip |
||
| 81 | end |
||
| 82 | |||
| 83 | tax_exempt = node_content_unless_nil(@transaction.at_css('taxExempt')) |
||
| 84 | unless tax_exempt.nil? |
||
| 85 | transaction.order ||= AuthorizeNet::Order.new() |
||
| 86 | transaction.order.tax_exempt = value_to_boolean(tax_exempt) |
||
| 87 | end |
||
| 88 | |||
| 89 | tax = @transaction.at_css('tax') |
||
| 90 | View Code Duplication | unless tax.nil? |
|
| 91 | transaction.order ||= AuthorizeNet::Order.new() |
||
| 92 | tax_amount = node_content_unless_nil(tax.at_css('amount')) |
||
| 93 | transaction.order.tax_amount = value_to_decimal(tax_amount) unless tax_amount.nil? |
||
| 94 | transaction.order.tax_name = node_content_unless_nil(tax.at_css('name')) |
||
| 95 | transaction.order.tax_description = node_content_unless_nil(tax.at_css('description')) |
||
| 96 | end |
||
| 97 | |||
| 98 | shipping = @transaction.at_css('shipping') |
||
| 99 | View Code Duplication | unless shipping.nil? |
|
| 100 | transaction.order ||= AuthorizeNet::Order.new() |
||
| 101 | shipping_amount = node_content_unless_nil(shipping.at_css('amount')) |
||
| 102 | transaction.order.shipping_amount = value_to_decimal(shipping_amount) unless shipping_amount.nil? |
||
| 103 | transaction.order.shipping_name = node_content_unless_nil(shipping.at_css('name')) |
||
| 104 | transaction.order.shipping_description = node_content_unless_nil(shipping.at_css('description')) |
||
| 105 | end |
||
| 106 | |||
| 107 | duty = @transaction.at_css('duty') |
||
| 108 | View Code Duplication | unless duty.nil? |
|
| 109 | transaction.order ||= AuthorizeNet::Order.new() |
||
| 110 | duty_amount = node_content_unless_nil(duty.at_css('amount')) |
||
| 111 | transaction.order.duty_amount = value_to_decimal(duty_amount) unless duty_amount.nil? |
||
| 112 | transaction.order.duty_name = node_content_unless_nil(duty.at_css('name')) |
||
| 113 | transaction.order.duty_description = node_content_unless_nil(duty.at_css('description')) |
||
| 114 | end |
||
| 115 | |||
| 116 | line_items = @transaction.at_css('lineItems') |
||
| 117 | unless line_items.nil? |
||
| 118 | transaction.order ||= AuthorizeNet::Order.new() |
||
| 119 | line_items.element_children.each do |child| |
||
| 120 | line_item = build_entity(child, Fields::LINE_ITEM_ENTITY_DESCRIPTION) |
||
| 121 | transaction.order.add_line_item(line_item) |
||
| 122 | end |
||
| 123 | end |
||
| 124 | |||
| 125 | # Really not sure what to do with customer type here. It should go on a payment |
||
| 126 | customer_type = node_content_unless_nil(@transaction.at_css('customer type')) |
||
| 127 | unless customer_type.nil? |
||
| 128 | transaction.customer ||= AuthorizeNet::CIM::CustomerProfile.new() |
||
| 129 | transaction.customer.payment_profiles = [AuthorizeNet::CIM::PaymentProfile.new(:cust_type => customer_type)] |
||
| 130 | end |
||
| 131 | |||
| 132 | subscription = @transaction.at_css('subscription') |
||
| 133 | View Code Duplication | unless subscription.nil? |
|
| 134 | subscription_id = node_content_unless_nil(@transaction.at_css('subscription').at_css('id')) |
||
| 135 | transaction.subscription_id = value_to_decimal(subscription_id) unless subscription_id.nil? |
||
| 136 | |||
| 137 | pay_num = node_content_unless_nil(@transaction.at_css('subscription').at_css('payNum')) |
||
| 138 | transaction.subscription_paynum = value_to_decimal(pay_num) unless pay_num.nil? |
||
| 139 | end |
||
| 140 | |||
| 141 | solution = @transaction.at_css('solution') |
||
| 142 | View Code Duplication | unless solution.nil? |
|
| 143 | solution_id = node_content_unless_nil(@transaction.at_css('solution').at_css('id')) |
||
| 144 | transaction.solution_id = value_to_decimal(solution_id) unless solution_id.nil? |
||
| 145 | |||
| 146 | transaction.solution_name = node_content_unless_nil(@transaction.at_css('solution').at_css('name')) |
||
| 147 | end |
||
| 148 | |||
| 149 | returned_items = @transaction.at_css('returnedItems') |
||
| 150 | unless returned_items.nil? |
||
| 151 | transaction.returns ||= AuthorizeNet::Reporting::ReturnedItem.new |
||
| 152 | returned_items.element_children.each do |child| |
||
| 153 | returned_item = build_entity(child, Fields::RETURNED_ITEM_ENTITY_DESCRIPTION) |
||
| 154 | transaction.returns.add_returned_item(returned_item) |
||
| 155 | end |
||
| 156 | end |
||
| 157 | |||
| 158 | return transaction |
||
| 159 | end |
||
| 160 | end |
||
| 161 | |||
| 163 | end |