| Conditions | 12 |
| Paths | 11 |
| Total Lines | 59 |
| Code Lines | 35 |
| Lines | 18 |
| Ratio | 30.51 % |
| 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 |
||
| 23 | public function checkForExclusions($coupon) |
||
| 24 | { |
||
| 25 | $countryCode = CountryPrice_EcommerceCountry::get_real_country(); |
||
| 26 | if ($countryCode) { |
||
| 27 | $countryCode = $countryCode->Code; |
||
| 28 | $includedCountries = $coupon->IncludedCountries(); |
||
| 29 | $excludedCountries = $coupon->ExcludedCountries(); |
||
| 30 | |||
| 31 | //first situation: no country information => ALLOW => return NULL to ignore this. |
||
| 32 | if ($includedCountries->count() == 0 && $excludedCountries->count() == 0) { |
||
| 33 | $this->owner->DebugString .= '--- no country rules apply ---'; |
||
| 34 | return null; |
||
| 35 | } |
||
| 36 | |||
| 37 | //second situation: includes and excludes |
||
| 38 | if ($includedCountries->count() > 0 && $excludedCountries->count() > 0) { |
||
| 39 | $this->owner->DebugString .= '--- inclusions and exclusions apply - checking for '.$countryCode.' ---'; |
||
| 40 | $returnFlag = true; |
||
| 41 | |||
| 42 | $includeArray = $includedCountries->column('Code'); |
||
| 43 | if (in_array($countryCode, $includeArray)) { |
||
| 44 | $returnFlag = null; |
||
| 45 | } |
||
| 46 | |||
| 47 | $excludeArray = $excludedCountries->column('Code'); |
||
| 48 | if (in_array($countryCode, $excludeArray)) { |
||
| 49 | $returnFlag = true; |
||
| 50 | } |
||
| 51 | |||
| 52 | return $returnFlag; |
||
| 53 | } |
||
| 54 | |||
| 55 | //third situation: is it included? |
||
| 56 | View Code Duplication | if ($includedCountries->count() > 0) { |
|
| 57 | $this->owner->DebugString .= '--- inclusions apply - checking for '.$countryCode.' ---'; |
||
| 58 | $includeArray = $includedCountries->column('Code'); |
||
| 59 | if (in_array($countryCode, $includeArray)) { |
||
| 60 | return null; |
||
| 61 | } else { |
||
| 62 | return true; |
||
| 63 | } |
||
| 64 | } |
||
| 65 | |||
| 66 | //fourth situation: is it excluded? |
||
| 67 | View Code Duplication | if ($excludedCountries->count() > 0) { |
|
| 68 | $this->owner->DebugString .= '--- exclusions apply - checking for '.$countryCode.' ---'; |
||
| 69 | $excludeArray = $excludedCountries->column('Code'); |
||
| 70 | if (in_array($countryCode, $excludeArray)) { |
||
| 71 | return true; |
||
| 72 | } else { |
||
| 73 | //return true; |
||
| 74 | } |
||
| 75 | } |
||
| 76 | } else { |
||
| 77 | $this->owner->DebugString .= '--- no country code could be found ---'; |
||
| 78 | } |
||
| 79 | |||
| 80 | return null; |
||
| 81 | } |
||
| 82 | } |
||
| 83 |
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.