| Conditions | 11 |
| Paths | 55 |
| Total Lines | 34 |
| Code Lines | 22 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 47 | public static function visitor_country() |
||
| 48 | { |
||
| 49 | $code = null; |
||
| 50 | if (Director::isDev()) { |
||
| 51 | if (isset($_GET['countryfortestingonly'])) { |
||
| 52 | $code = $_GET['countryfortestingonly']; |
||
| 53 | Session::set("countryfortestingonly", $code); |
||
| 54 | } |
||
| 55 | if ($code = Session::get("countryfortestingonly")) { |
||
| 56 | Session::set("MyCloudFlareCountry", $code); |
||
| 57 | } |
||
| 58 | } |
||
| 59 | if (!$code) { |
||
| 60 | if (isset($_SERVER["HTTP_CF_IPCOUNTRY"]) && $_SERVER["HTTP_CF_IPCOUNTRY"]) { |
||
| 61 | return $_SERVER["HTTP_CF_IPCOUNTRY"]; |
||
| 62 | } else { |
||
| 63 | $code = Session::get("MyCloudFlareCountry"); |
||
| 64 | if (!$code) { |
||
| 65 | if ($address = self::get_remote_address()) { |
||
| 66 | $code = CloudFlareGeoip::ip2country($address, true); |
||
| 67 | } |
||
| 68 | if (!$code) { |
||
| 69 | $code = self::get_default_country_code(); |
||
| 70 | } |
||
| 71 | if (!$code) { |
||
| 72 | $code = Config::inst()->get("EcommerceCountry", "default_country_code"); |
||
| 73 | } |
||
| 74 | Session::set("MyCloudFlareCountry", $code); |
||
| 75 | } |
||
| 76 | } |
||
| 77 | } |
||
| 78 | |||
| 79 | return $code; |
||
| 80 | } |
||
| 81 | |||
| 103 |
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.