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