| Conditions | 11 |
| Paths | 55 |
| Total Lines | 33 |
| Code Lines | 21 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 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 |
||
| 57 | public static function visitor_country() |
||
| 58 | { |
||
| 59 | $code = null; |
||
| 60 | if (Director::isDev()) { |
||
| 61 | if (isset($_GET['countryfortestingonly'])) { |
||
| 62 | $code = $_GET['countryfortestingonly']; |
||
| 63 | Controller::curr()->getRequest()->getSession()->set('countryfortestingonly', $code); |
||
| 64 | } |
||
| 65 | if ($code = Controller::curr()->getRequest()->getSession()->get('countryfortestingonly')) { |
||
| 66 | Controller::curr()->getRequest()->getSession()->set('MyCloudFlareCountry', $code); |
||
| 67 | } |
||
| 68 | } |
||
| 69 | if (! $code) { |
||
| 70 | if (isset($_SERVER['HTTP_CF_IPCOUNTRY']) && $_SERVER['HTTP_CF_IPCOUNTRY']) { |
||
| 71 | return $_SERVER['HTTP_CF_IPCOUNTRY']; |
||
| 72 | } |
||
| 73 | $code = Controller::curr()->getRequest()->getSession()->get('MyCloudFlareCountry'); |
||
| 74 | if (! $code) { |
||
| 75 | $address = self::get_remote_address(); |
||
| 76 | if (strlen($address) > 3) { |
||
| 77 | $code = CloudFlareGeoIP::ip2country($address, true); |
||
| 78 | } |
||
| 79 | if (! $code) { |
||
| 80 | $code = self::get_default_country_code(); |
||
| 81 | } |
||
| 82 | if ('' === $code) { |
||
| 83 | $code = Config::inst()->get('CloudFlareGeoip', 'default_country_code'); |
||
| 84 | } |
||
| 85 | Controller::curr()->getRequest()->getSession()->set('MyCloudFlareCountry', $code); |
||
| 86 | } |
||
| 87 | } |
||
| 88 | |||
| 89 | return $code; |
||
| 90 | } |
||
| 114 |