| Total Complexity | 6 |
| Total Lines | 34 |
| Duplicated Lines | 70.59 % |
| Changes | 0 | ||
Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | module AuthorizeNet::ARB |
||
| 2 | class SubscriptionListResponse < AuthorizeNet::XmlResponse |
||
| 3 | # Constructs a new response object from a +raw_response. You don't typically |
||
| 4 | # construct this object yourself, as AuthorizeNet::ARB::Transaction will |
||
| 5 | # build one for you when it makes the request to the gateway. |
||
| 6 | View Code Duplication | def initialize(raw_response, transaction) |
|
|
|
|||
| 7 | super |
||
| 8 | unless connection_failure? |
||
| 9 | begin |
||
| 10 | @subscription_details = @root.at_css('subscriptionDetails') |
||
| 11 | @subscription_detail = @root.at_css('subscriptionDetail') |
||
| 12 | @total_num_in_resultset = node_content_unless_nil(@root.at_css('totalNumInResultSet')) |
||
| 13 | rescue StandardError |
||
| 14 | @raw_response = $ERROR_INFO |
||
| 15 | end |
||
| 16 | end |
||
| 17 | end |
||
| 18 | |||
| 19 | # Returns total number of subscriptions matching the search criteria |
||
| 20 | attr_reader :total_num_in_resultset |
||
| 21 | |||
| 22 | # Returns an Array of SubscriptionDetail objects built from the entities returned in the response. Returns nil if no subscriptions were returned. |
||
| 23 | View Code Duplication | def subscription_details |
|
| 24 | unless @subscription_details.nil? |
||
| 25 | subscription_details = [] |
||
| 26 | @subscription_details.element_children.each do |child| |
||
| 27 | next if child.nil? |
||
| 28 | subscription_detail = build_entity(child, Fields::SUBSCRIPTION_DETAIL_ENTITY_DESCRIPTION) |
||
| 29 | |||
| 30 | subscription_details <<= subscription_detail |
||
| 31 | end |
||
| 32 | return subscription_details unless subscription_details.empty? |
||
| 33 | end |
||
| 34 | end |
||
| 35 | end |
||
| 36 | end |
||
| 37 |