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