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