Conditions | 41 |
Paths | 17094 |
Total Lines | 137 |
Lines | 45 |
Ratio | 32.85 % |
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 |
||
224 | public function updateBeforeCalculatedPrice($price = null) |
||
225 | { |
||
226 | $countryCode = ''; |
||
227 | $countryObject = CountryPrice_EcommerceCountry::get_real_country(); |
||
228 | if ($countryObject) { |
||
229 | $countryCode = $countryObject->Code; |
||
230 | } |
||
231 | if ($countryCode === '' || $countryCode === EcommerceConfig::get('EcommerceCountry', 'default_country_code')) { |
||
232 | if ($this->debug) { |
||
233 | debug::log('No country code or default country code: '.$countryCode); |
||
234 | } |
||
235 | |||
236 | return null; |
||
237 | } |
||
238 | $key = $this->owner->ClassName."___".$this->owner->ID.'____'.$countryCode; |
||
239 | if (! isset(self::$_buyable_price[$key])) { |
||
240 | //basics |
||
241 | $currency = null; |
||
242 | $currencyCode = null; |
||
243 | |||
244 | if ($countryCode) { |
||
245 | $order = ShoppingCart::current_order(); |
||
246 | //if the order has never been localised, then we do this now!!!! |
||
247 | if (count(self::$_buyable_price) === 0) { |
||
248 | CountryPrice_OrderDOD::localise_order($countryCode, $force = false, $runAgain = true); |
||
249 | |||
250 | // CRUCIAL!!!! |
||
251 | // reload order with new values! |
||
252 | $order = ShoppingCart::current_order(); |
||
253 | } |
||
254 | if ($order && $order->exists()) { |
||
255 | $currency = $order->CurrencyUsed(); |
||
256 | } |
||
257 | if ($currency && $currency->exists()) { |
||
258 | //do nothing |
||
259 | } else { |
||
260 | $currency = CountryPrice_EcommerceCurrency::get_currency_for_country($countryCode); |
||
261 | } |
||
262 | if ($currency) { |
||
263 | $currencyCode = strtoupper($currency->Code); |
||
264 | //1. exact price for country |
||
265 | View Code Duplication | if ($currencyCode) { |
|
266 | $prices = $this->owner->CountryPricesForCountryAndCurrency( |
||
267 | $countryCode, |
||
268 | $currencyCode |
||
269 | ); |
||
270 | if ($prices && $prices->count() == 1) { |
||
271 | self::$_buyable_price[$key] = $prices->First()->Price; |
||
272 | return self::$_buyable_price[$key]; |
||
273 | } elseif ($prices) { |
||
274 | if ($this->debug) { |
||
275 | debug::log('MAIN COUNTRY: There is an error number of prices: '.$prices->count().' based on a search for '.$countryCode.' - '.$currencyCode); |
||
276 | } |
||
277 | } else { |
||
278 | if ($this->debug) { |
||
279 | debug::log('MAIN COUNTRY: There is no country price: '); |
||
280 | } |
||
281 | } |
||
282 | } else { |
||
283 | if ($this->debug) { |
||
284 | debug::log('MAIN COUNTRY: There is no currency code '.$currencyCode.''); |
||
285 | } |
||
286 | } |
||
287 | } else { |
||
288 | if ($this->debug) { |
||
289 | debug::log('MAIN COUNTRY: there is no currency'); |
||
290 | } |
||
291 | } |
||
292 | if (Config::inst()->get('CountryPrice_BuyableExtension', 'allow_usage_of_distributor_backup_country_pricing')) { |
||
293 | //there is a specific country price ... |
||
294 | //check for distributor primary country price |
||
295 | // if it is the same currency, then use that one ... |
||
296 | $distributorCountry = CountryPrice_EcommerceCountry::get_distributor_primary_country($countryCode); |
||
297 | if ($distributorCurrency = $distributorCountry->EcommerceCurrency()) { |
||
298 | if ($distributorCurrency->ID == $currency->ID) { |
||
299 | $distributorCurrencyCode = strtoupper($distributorCurrency->Code); |
||
300 | $distributorCountryCode = $distributorCountry->Code; |
||
301 | View Code Duplication | if ($distributorCurrencyCode && $distributorCountryCode) { |
|
302 | $prices = $this->owner->CountryPricesForCountryAndCurrency( |
||
303 | $distributorCountryCode, |
||
304 | $distributorCurrencyCode |
||
305 | ); |
||
306 | if ($prices && $prices->count() == 1) { |
||
307 | self::$_buyable_price[$key] = $prices->First()->Price; |
||
308 | |||
309 | return self::$_buyable_price[$key]; |
||
310 | } elseif ($prices) { |
||
311 | if ($this->debug) { |
||
312 | debug::log('BACKUP COUNTRY: There is an error number of prices: '.$prices->count()); |
||
313 | } |
||
314 | } else { |
||
315 | if ($this->debug) { |
||
316 | debug::log('BACKUP COUNTRY: There is no country price: '); |
||
317 | } |
||
318 | } |
||
319 | } else { |
||
320 | if ($this->debug) { |
||
321 | debug::log('BACKUP COUNTRY: We are missing the distributor currency code ('.$distributorCurrencyCode.') or the distributor country code ('.$distributorCountryCode.')'); |
||
322 | } |
||
323 | } |
||
324 | } else { |
||
325 | if ($this->debug) { |
||
326 | debug::log('BACKUP COUNTRY: The distributor currency ID ('.$distributorCurrency->ID.') is not the same as the order currency ID ('.$currency->ID.').'); |
||
327 | } |
||
328 | } |
||
329 | } |
||
330 | } else { |
||
331 | if ($this->debug) { |
||
332 | debug::log('We do not allow backup country pricing'); |
||
333 | } |
||
334 | } |
||
335 | } else { |
||
336 | if ($this->debug) { |
||
337 | debug::log('There is not Country Code '); |
||
338 | } |
||
339 | } |
||
340 | //order must have a country and a currency |
||
341 | if (! $currencyCode || ! $countryCode) { |
||
342 | if ($this->debug) { |
||
343 | debug::log('No currency ('.$currencyCode.') or no country code ('.$countryCode.') for order: '); |
||
344 | } |
||
345 | } |
||
346 | //catch error 2: no country price BUT currency is not default currency ... |
||
347 | if (EcommercePayment::site_currency() != $currencyCode) { |
||
348 | if ($this->debug) { |
||
349 | debug::log('site currency ('.EcommercePayment::site_currency().') is not the same order currency ('.$currencyCode.')'); |
||
350 | } |
||
351 | } else { |
||
352 | if ($this->debug) { |
||
353 | debug::log('SETTING '.$key.' to ZERO - NOT FOR SALE'); |
||
354 | } |
||
355 | } |
||
356 | self::$_buyable_price[$key] = 0; |
||
357 | } |
||
358 | |||
359 | return self::$_buyable_price[$key]; |
||
360 | } |
||
361 | |||
445 |
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.