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 | 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 = parse_url( $option_url ); |
||
128 | $url = parse_url( $url ); |
||
129 | |||
130 | if ( $normalize_www ) { |
||
131 | View Code Duplication | if ( $url['host'] === "www.{$option_url[ 'host' ]}" ) { |
|
132 | // remove www if not present in option URL |
||
133 | $url['host'] = $option_url['host']; |
||
134 | } |
||
135 | View Code Duplication | if ( $option_url['host'] === "www.{$url[ 'host' ]}" ) { |
|
136 | // add www if present in option URL |
||
137 | $url['host'] = $option_url['host']; |
||
138 | } |
||
139 | } |
||
140 | |||
141 | if ( $url['host'] === $option_url['host'] ) { |
||
142 | $url['scheme'] = $option_url['scheme']; |
||
143 | // return set_url_scheme( $current_url, $option_url['scheme'] ); |
||
144 | } |
||
145 | |||
146 | $normalized_url = "{$url['scheme']}://{$url['host']}"; |
||
147 | |||
148 | if ( isset( $url['path'] ) ) { |
||
149 | $normalized_url .= "{$url['path']}"; |
||
150 | } |
||
151 | |||
152 | if ( isset( $url['query'] ) ) { |
||
153 | $normalized_url .= "?{$url['query']}"; |
||
154 | } |
||
155 | |||
156 | return $normalized_url; |
||
157 | } |
||
158 | |||
174 |