| Conditions | 12 |
| Paths | 168 |
| Total Lines | 51 |
| Code Lines | 28 |
| Lines | 8 |
| Ratio | 15.69 % |
| 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 |
||
| 111 | public static function preserve_scheme( $option, $url_function, $normalize_www = false ) { |
||
| 112 | $previous_https_value = isset( $_SERVER['HTTPS'] ) ? $_SERVER['HTTPS'] : null; |
||
| 113 | $_SERVER['HTTPS'] = 'off'; |
||
| 114 | $url = call_user_func( $url_function ); |
||
| 115 | $option_url = get_option( $option ); |
||
| 116 | if ( $previous_https_value ) { |
||
| 117 | $_SERVER['HTTPS'] = $previous_https_value; |
||
| 118 | } else { |
||
| 119 | unset( $_SERVER['HTTPS'] ); |
||
| 120 | } |
||
| 121 | |||
| 122 | if ( $option_url === $url ) { |
||
| 123 | return $url; |
||
| 124 | } |
||
| 125 | |||
| 126 | // turn them both into parsed format |
||
| 127 | $option_url = wp_parse_url( $option_url ); |
||
| 128 | $url = wp_parse_url( $url ); |
||
| 129 | |||
| 130 | if ( ! $option_url || ! $url ) { |
||
| 131 | return $url; |
||
| 132 | } |
||
| 133 | |||
| 134 | if ( $normalize_www ) { |
||
| 135 | View Code Duplication | if ( $url['host'] === "www.{$option_url[ 'host' ]}" ) { |
|
| 136 | // remove www if not present in option URL |
||
| 137 | $url['host'] = $option_url['host']; |
||
| 138 | } |
||
| 139 | View Code Duplication | if ( $option_url['host'] === "www.{$url[ 'host' ]}" ) { |
|
| 140 | // add www if present in option URL |
||
| 141 | $url['host'] = $option_url['host']; |
||
| 142 | } |
||
| 143 | } |
||
| 144 | |||
| 145 | if ( $url['host'] === $option_url['host'] ) { |
||
| 146 | $url['scheme'] = $option_url['scheme']; |
||
| 147 | // return set_url_scheme( $current_url, $option_url['scheme'] ); |
||
| 148 | } |
||
| 149 | |||
| 150 | $normalized_url = "{$url['scheme']}://{$url['host']}"; |
||
| 151 | |||
| 152 | if ( isset( $url['path'] ) ) { |
||
| 153 | $normalized_url .= "{$url['path']}"; |
||
| 154 | } |
||
| 155 | |||
| 156 | if ( isset( $url['query'] ) ) { |
||
| 157 | $normalized_url .= "?{$url['query']}"; |
||
| 158 | } |
||
| 159 | |||
| 160 | return $normalized_url; |
||
| 161 | } |
||
| 162 | |||
| 186 |