| Conditions | 11 |
| Paths | 15 |
| Total Lines | 29 |
| Code Lines | 18 |
| 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 |
||
| 41 | public static function absoluteUrlWithProtocol($url) |
||
| 42 | { |
||
| 43 | // Make this a full URL |
||
| 44 | if (!self::isAbsoluteUrl($url)) { |
||
| 45 | $protocol = "http"; |
||
| 46 | if (isset($_SERVER['HTTPS']) && (strcasecmp($_SERVER['HTTPS'], 'on') === 0 || $_SERVER['HTTPS'] == 1) |
||
| 47 | || isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && strcasecmp($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') === 0 |
||
| 48 | ) { |
||
| 49 | $protocol = "https"; |
||
| 50 | } |
||
| 51 | if (self::isProtocolRelativeUrl($url)) { |
||
| 52 | try { |
||
| 53 | $url = self::urlWithScheme($url, $protocol); |
||
| 54 | } catch (SiteNotFoundException $e) { |
||
| 55 | Craft::error($e->getMessage(), __METHOD__); |
||
| 56 | } |
||
| 57 | } else { |
||
| 58 | try { |
||
| 59 | $url = self::siteUrl($url, null, $protocol); |
||
| 60 | if (self::isProtocolRelativeUrl($url)) { |
||
| 61 | $url = self::urlWithScheme($url, $protocol); |
||
| 62 | } |
||
| 63 | } catch (Exception $e) { |
||
| 64 | Craft::error($e->getMessage(), __METHOD__); |
||
| 65 | } |
||
| 66 | } |
||
| 67 | } |
||
| 68 | |||
| 69 | return $url; |
||
| 70 | } |
||
| 72 |