| 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 |
||
| 111 | self::normalize_www_in_url( 'siteurl', 'site_url' ) |
||
| 112 | ); |
||
| 113 | } |
||
| 114 | |||
| 115 | public static function main_network_site_url() { |
||
| 116 | return self::get_protocol_normalized_url( 'main_network_site_url', network_site_url() ); |
||
| 117 | } |
||
| 118 | |||
| 119 | public static function get_protocol_normalized_url( $callable, $new_value ) { |
||
| 120 | $option_key = self::HTTPS_CHECK_OPTION_PREFIX . $callable; |
||
| 121 | |||
| 122 | $parsed_url = wp_parse_url( $new_value ); |
||
| 123 | if ( ! $parsed_url ) { |
||
| 124 | return $new_value; |
||
| 125 | } |
||
| 126 | |||
| 127 | $scheme = $parsed_url['scheme']; |
||
| 128 | $scheme_history = get_option( $option_key, array() ); |
||
| 129 | $scheme_history[] = $scheme; |
||
| 130 | |||
| 131 | // Limit length to self::HTTPS_CHECK_HISTORY |
||
| 132 | $scheme_history = array_slice( $scheme_history, ( self::HTTPS_CHECK_HISTORY * -1 ) ); |
||
| 133 | |||
| 134 | update_option( $option_key, $scheme_history ); |
||
| 135 | |||
| 136 | $forced_scheme = in_array( 'https', $scheme_history ) ? 'https' : 'http'; |
||
| 137 | |||
| 138 | return set_url_scheme( $new_value, $forced_scheme ); |
||
| 139 | } |
||
| 140 | |||
| 141 | public static function normalize_www_in_url( $option, $url_function ) { |
||
| 142 | $url = wp_parse_url( call_user_func( $url_function ) ); |
||
| 143 | $option_url = wp_parse_url( get_option( $option ) ); |
||
| 144 | |||
| 145 | if ( ! $option_url || ! $url ) { |
||
| 146 | return $url; |
||
| 147 | } |
||
| 148 | |||
| 149 | View Code Duplication | if ( $url[ 'host' ] === "www.{$option_url[ 'host' ]}" ) { |
|
| 150 | // remove www if not present in option URL |
||
| 151 | $url[ 'host' ] = $option_url[ 'host' ]; |
||
| 152 | } |
||
| 153 | View Code Duplication | if ( $option_url[ 'host' ] === "www.{$url[ 'host' ]}" ) { |
|
| 154 | // add www if present in option URL |
||
| 155 | $url[ 'host' ] = $option_url[ 'host' ]; |
||
| 156 | } |
||
| 157 | |||
| 158 | $normalized_url = "{$url['scheme']}://{$url['host']}"; |
||
| 193 |