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