Conditions | 24 |
Paths | 1524 |
Total Lines | 84 |
Lines | 0 |
Ratio | 0 % |
Changes | 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:
1 | <?php |
||
55 | public static function localise_order($countryCode = null, $force = false, $runAgain = false) |
||
56 | { |
||
57 | $countryCode = EcommerceCountry::get_country_from_mixed_var($countryCode, true); |
||
58 | |||
59 | if (self::$_number_of_times_we_have_run_localise_order > 0) { |
||
60 | $runAgain = false; |
||
61 | } |
||
62 | if ($runAgain) { |
||
63 | self::$_number_of_times_we_have_run_localise_order = 0; |
||
64 | } |
||
65 | if (self::$_number_of_times_we_have_run_localise_order > 2) { |
||
66 | return; |
||
67 | } |
||
68 | |||
69 | self::$_number_of_times_we_have_run_localise_order++; |
||
70 | $order = ShoppingCart::current_order(); |
||
71 | if ($order && $order->exists()) { |
||
72 | if ($order->IsSubmitted()) { |
||
73 | return true; |
||
74 | } |
||
75 | if (! $countryCode) { |
||
76 | $countryCode = $order->getCountry(); |
||
77 | } |
||
78 | $currencyObject = CountryPrice_EcommerceCurrency::get_currency_for_country($countryCode); |
||
79 | if (Config::inst()->get('CountryPrice_OrderDOD', 'only_allow_within_country_sales')) { |
||
80 | $distributor = $order->getDistributor($countryCode); |
||
81 | $countryOptions = $distributor->Countries(); |
||
82 | if ($countryOptions && $countryOptions->count()) { |
||
83 | EcommerceCountry::set_for_current_order_only_show_countries($countryOptions->column('Code')); |
||
84 | } |
||
85 | } |
||
86 | //check if the billing and shipping address have a country so that they will not be overridden by previous Orders |
||
87 | //we do this to make sure that the previous address can not change the region and thereby destroy the order in the cart |
||
88 | if ($billingAddress = $order->CreateOrReturnExistingAddress('BillingAddress')) { |
||
89 | if (! $billingAddress->Country || $force) { |
||
90 | $billingAddress->Country = $countryCode; |
||
91 | $billingAddress->write(); |
||
92 | } |
||
93 | } |
||
94 | if ($shippingAddress = $order->CreateOrReturnExistingAddress('ShippingAddress')) { |
||
95 | if (! $shippingAddress->ShippingCountry || $force) { |
||
96 | $shippingAddress->ShippingCountry = $countryCode; |
||
97 | $shippingAddress->write(); |
||
98 | } |
||
99 | } |
||
100 | |||
101 | //if a country code and currency has been set then all is good |
||
102 | //from there we keep it this way |
||
103 | if ( |
||
104 | $order->OriginatingCountryCode == $countryCode && |
||
105 | $order->CurrencyUsedID == $currencyObject->ID |
||
106 | ) { |
||
107 | return true; |
||
108 | } |
||
109 | $order->resetLocale = true; |
||
110 | $order->write(); |
||
111 | $order = Order::get()->byID($order->ID); |
||
112 | $orderHasBeenChanged = false; |
||
113 | |||
114 | //check currency ... |
||
115 | if ($order->CurrencyUsedID != $currencyObject->ID) { |
||
116 | $order->SetCurrency($currencyObject); |
||
117 | $orderHasBeenChanged = true; |
||
118 | } |
||
119 | if ($orderHasBeenChanged) { |
||
120 | ShoppingCart::reset_order_reference(); |
||
121 | $order->write(); |
||
122 | $items = $order->OrderItems(); |
||
123 | if ($items) { |
||
124 | foreach ($items as $item) { |
||
125 | $buyable = $item->Buyable(true); |
||
126 | if (! $buyable->canPurchase()) { |
||
127 | $item->delete(); |
||
128 | } |
||
129 | } |
||
130 | } |
||
131 | // Called after because some modifiers use the country field to calculate the values |
||
132 | $order->calculateOrderAttributes(true); |
||
133 | } |
||
134 | self::localise_order($countryCode); |
||
135 | } else { |
||
136 | Session::set('temporary_country_order_store', $countryCode); |
||
137 | } |
||
138 | } |
||
139 | |||
319 |
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.