Conditions | 11 |
Paths | 55 |
Total Lines | 32 |
Code Lines | 20 |
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 |
||
52 | public static function visitor_country() |
||
53 | { |
||
54 | $code = null; |
||
55 | if (Director::isDev()) { |
||
56 | if (isset($_GET['countryfortestingonly'])) { |
||
57 | $code = $_GET['countryfortestingonly']; |
||
58 | Controller::curr()->getRequest()->getSession()->set('countryfortestingonly', $code); |
||
59 | } |
||
60 | if ($code = Controller::curr()->getRequest()->getSession()->get('countryfortestingonly')) { |
||
61 | Controller::curr()->getRequest()->getSession()->set('MyCloudFlareCountry', $code); |
||
62 | } |
||
63 | } |
||
64 | if (! $code) { |
||
65 | if (isset($_SERVER['HTTP_CF_IPCOUNTRY']) && $_SERVER['HTTP_CF_IPCOUNTRY']) { |
||
66 | return $_SERVER['HTTP_CF_IPCOUNTRY']; |
||
67 | } |
||
68 | $code = Controller::curr()->getRequest()->getSession()->get('MyCloudFlareCountry'); |
||
69 | if (! $code) { |
||
70 | if ($address = self::get_remote_address()) { |
||
71 | $code = CloudFlareGeoip::ip2country($address, true); |
||
72 | } |
||
73 | if (! $code) { |
||
74 | $code = self::get_default_country_code(); |
||
75 | } |
||
76 | if (! $code) { |
||
77 | $code = Config::inst()->get('CloudFlareGeoip', 'default_country_code'); |
||
78 | } |
||
79 | Controller::curr()->getRequest()->getSession()->set('MyCloudFlareCountry', $code); |
||
80 | } |
||
81 | } |
||
82 | |||
83 | return $code; |
||
84 | } |
||
106 |