Conditions | 36 |
Paths | 1104 |
Total Lines | 128 |
Code Lines | 84 |
Lines | 24 |
Ratio | 18.75 % |
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 |
||
206 | public function updateBeforeCalculatedPrice($price = null) |
||
207 | { |
||
208 | $countryCode = ''; |
||
209 | $countryObject = CountryPrice_EcommerceCountry::get_real_country(); |
||
210 | if ($countryObject) { |
||
211 | $countryCode = $countryObject->Code; |
||
212 | } |
||
213 | if ($countryCode == '' || $countryCode == EcommerceConfig::get('EcommerceCountry', 'default_country_code')) { |
||
214 | if ($this->debug) { |
||
215 | debug::log('No country code or default country code: '.$countryCode); |
||
216 | } |
||
217 | |||
218 | return null; |
||
219 | } |
||
220 | $key = $this->owner->ClassName."___".$this->owner->ID.'____'.$countryCode; |
||
221 | if (! isset(self::$_buyable_price[$key])) { |
||
222 | //basics |
||
223 | $currency = null; |
||
224 | $currencyCode = null; |
||
225 | |||
226 | if ($countryCode) { |
||
227 | $order = ShoppingCart::current_order(); |
||
228 | CountryPrice_OrderDOD::localise_order(); |
||
229 | $currency = $order->CurrencyUsed(); |
||
230 | if ($currency) { |
||
231 | $currencyCode = strtoupper($currency->Code); |
||
232 | //1. exact price for country |
||
233 | if ($currencyCode) { |
||
234 | $prices = $this->owner->CountryPricesForCountryAndCurrency( |
||
235 | $countryCode, |
||
236 | $currencyCode |
||
237 | ); |
||
238 | View Code Duplication | if ($prices && $prices->count() == 1) { |
|
239 | self::$_buyable_price[$key] = $prices->First()->Price; |
||
240 | return self::$_buyable_price[$key]; |
||
241 | } elseif ($prices) { |
||
242 | if ($this->debug) { |
||
243 | debug::log('MAIN COUNTRY: There is an error number of prices: '.$prices->count()); |
||
244 | } |
||
245 | } else { |
||
246 | if ($this->debug) { |
||
247 | debug::log('MAIN COUNTRY: There is no country price: '); |
||
248 | } |
||
249 | } |
||
250 | } else { |
||
251 | if ($this->debug) { |
||
252 | debug::log('MAIN COUNTRY: There is no currency code '.$currencyCode.''); |
||
253 | } |
||
254 | } |
||
255 | } else { |
||
256 | if ($this->debug) { |
||
257 | debug::log('MAIN COUNTRY: there is no currency'); |
||
258 | } |
||
259 | } |
||
260 | if (Config::inst()->get('CountryPrice_BuyableExtension', 'allow_usage_of_distributor_backup_country_pricing')) { |
||
261 | //there is a specific country price ... |
||
262 | //check for distributor primary country price |
||
263 | // if it is the same currency, then use that one ... |
||
264 | $distributorCountry = CountryPrice_EcommerceCountry::get_distributor_primary_country($countryCode); |
||
265 | if ($distributorCurrency = $distributorCountry->EcommerceCurrency()) { |
||
266 | if ($distributorCurrency->ID == $currency->ID) { |
||
267 | $distributorCurrencyCode = strtoupper($distributorCurrency->Code); |
||
268 | $distributorCountryCode = $distributorCountry->Code; |
||
269 | if ($distributorCurrencyCode && $distributorCountryCode) { |
||
270 | $prices = $this->owner->CountryPricesForCountryAndCurrency( |
||
271 | $distributorCountryCode, |
||
272 | $distributorCurrencyCode |
||
273 | ); |
||
274 | View Code Duplication | if ($prices && $prices->count() == 1) { |
|
275 | self::$_buyable_price[$key] = $prices->First()->Price; |
||
276 | |||
277 | return self::$_buyable_price[$key]; |
||
278 | } elseif ($prices) { |
||
279 | if ($this->debug) { |
||
280 | debug::log('BACKUP COUNTRY: There is an error number of prices: '.$prices->count()); |
||
281 | } |
||
282 | } else { |
||
283 | if ($this->debug) { |
||
284 | debug::log('BACKUP COUNTRY: There is no country price: '); |
||
285 | } |
||
286 | } |
||
287 | } else { |
||
288 | if ($this->debug) { |
||
289 | debug::log('BACKUP COUNTRY: We are missing the distributor currency code ('.$distributorCurrencyCode.') or the distributor country code ('.$distributorCountryCode.')'); |
||
290 | } |
||
291 | } |
||
292 | } else { |
||
293 | if ($this->debug) { |
||
294 | debug::log('BACKUP COUNTRY: The distributor currency ID ('.$distributorCurrency->ID.') is not the same as the order currency ID ('.$currency->ID.').'); |
||
295 | } |
||
296 | } |
||
297 | } |
||
298 | } else { |
||
299 | if ($this->debug) { |
||
300 | debug::log('We do not allow backup country pricing'); |
||
301 | } |
||
302 | } |
||
303 | } else { |
||
304 | if ($this->debug) { |
||
305 | debug::log('There is not Country Code '); |
||
306 | } |
||
307 | } |
||
308 | //order must have a country and a currency |
||
309 | if (! $currencyCode || ! $countryCode) { |
||
310 | if ($this->debug) { |
||
311 | debug::log('No currency ('.$currencyCode.') or no country code ('.$countryCode.') for order: '); |
||
312 | } |
||
313 | self::$_buyable_price[$key] = 0; |
||
314 | return self::$_buyable_price[$key]; |
||
315 | } |
||
316 | //catch error 2: no country price BUT currency is not default currency ... |
||
317 | if (EcommercePayment::site_currency() != $currencyCode) { |
||
318 | if ($this->debug) { |
||
319 | debug::log('site currency ('.EcommercePayment::site_currency().') is not the same order currency ('.$currencyCode.')'); |
||
320 | } |
||
321 | self::$_buyable_price[$key] = 0; |
||
322 | return self::$_buyable_price[$key]; |
||
323 | } |
||
324 | if ($this->debug) { |
||
325 | debug::log('SETTING '.$key.' to ZERO - NOT FOR SALE'); |
||
326 | } |
||
327 | self::$_buyable_price[$key] = 0; |
||
328 | |||
329 | return self::$_buyable_price[$key]; |
||
330 | } |
||
331 | |||
332 | return self::$_buyable_price[$key]; |
||
333 | } |
||
334 | |||
418 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.