| Conditions | 10 |
| Paths | 164 |
| Total Lines | 47 |
| Code Lines | 26 |
| Lines | 8 |
| Ratio | 17.02 % |
| Changes | 1 | ||
| 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 |
||
| 95 | public static function preserve_scheme( $option, $url_function, $normalize_www = false ) { |
||
| 96 | $previous_https_value = isset( $_SERVER['HTTPS'] ) ? $_SERVER['HTTPS'] : null; |
||
| 97 | $_SERVER['HTTPS'] = 'off'; |
||
| 98 | $url = call_user_func( $url_function ); |
||
| 99 | $option_url = get_option( $option ); |
||
| 100 | if ( $previous_https_value ) { |
||
| 101 | $_SERVER['HTTPS'] = $previous_https_value; |
||
| 102 | } else { |
||
| 103 | unset( $_SERVER['HTTPS'] ); |
||
| 104 | } |
||
| 105 | |||
| 106 | if ( $option_url === $url ) { |
||
| 107 | return $url; |
||
| 108 | } |
||
| 109 | |||
| 110 | // turn them both into parsed format |
||
| 111 | $option_url = parse_url( $option_url ); |
||
| 112 | $url = parse_url( $url ); |
||
| 113 | |||
| 114 | if ( $normalize_www ) { |
||
| 115 | View Code Duplication | if ( $url['host'] === "www.{$option_url[ 'host' ]}" ) { |
|
| 116 | // remove www if not present in option URL |
||
| 117 | $url['host'] = $option_url['host']; |
||
| 118 | } |
||
| 119 | View Code Duplication | if ( $option_url['host'] === "www.{$url[ 'host' ]}" ) { |
|
| 120 | // add www if present in option URL |
||
| 121 | $url['host'] = $option_url['host']; |
||
| 122 | } |
||
| 123 | } |
||
| 124 | |||
| 125 | if ( $url['host'] === $option_url['host'] ) { |
||
| 126 | $url['scheme'] = $option_url['scheme']; |
||
| 127 | // return set_url_scheme( $current_url, $option_url['scheme'] ); |
||
| 128 | } |
||
| 129 | |||
| 130 | $normalized_url = "{$url['scheme']}://{$url['host']}"; |
||
| 131 | |||
| 132 | if ( isset( $url['path'] ) ) { |
||
| 133 | $normalized_url .= "{$url['path']}"; |
||
| 134 | } |
||
| 135 | |||
| 136 | if ( isset( $url['query'] ) ) { |
||
| 137 | $normalized_url .= "?{$url['query']}"; |
||
| 138 | } |
||
| 139 | |||
| 140 | return $normalized_url; |
||
| 141 | } |
||
| 142 | |||
| 158 |