compability.php ➔ http_build_url()   C
last analyzed

Complexity

Conditions 11
Paths 1024

Size

Total Lines 13
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 11
eloc 11
nc 1024
nop 1
dl 0
loc 13
rs 5.5714
c 0
b 0
f 0

How to fix   Complexity   

Long Method

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:

1
<?php
2
/**
3
 * Adds compability for missing methods
4
 *
5
 * @package imgix
6
 */
7
8
if ( ! function_exists( 'http_build_url' ) ) {
9
	/**
10
	 * This is a simplified version of http_build_url if pecl_http is missing
11
	 *
12
	 * @param array $parsed_url
13
	 *
14
	 * @return string
15
	 */
16
	function http_build_url( $parsed_url ) {
17
		$scheme   = isset( $parsed_url['scheme'] ) ? $parsed_url['scheme'] . '://' : '';
18
		$host     = isset( $parsed_url['host'] ) ? $parsed_url['host'] : '';
19
		$port     = isset( $parsed_url['port'] ) ? ':' . $parsed_url['port'] : '';
20
		$user     = isset( $parsed_url['user'] ) ? $parsed_url['user'] : '';
21
		$pass     = isset( $parsed_url['pass'] ) ? ':' . $parsed_url['pass'] : '';
22
		$pass     = ( $user || $pass ) ? "$pass@" : '';
23
		$path     = isset( $parsed_url['path'] ) ? $parsed_url['path'] : '';
24
		$query    = isset( $parsed_url['query'] ) ? '?' . $parsed_url['query'] : '';
25
		$fragment = isset( $parsed_url['fragment'] ) ? '#' . $parsed_url['fragment'] : '';
26
27
		return "$scheme$user$pass$host$port$path$query$fragment";
28
	}
29
}
30
31
if ( ! function_exists( 'wp_get_additional_image_sizes' ) ) {
32
	/**
33
	 * Retrieve additional image sizes.
34
	 *
35
	 * @since 4.7.0
36
	 *
37
	 * @global array $_wp_additional_image_sizes
38
	 *
39
	 * @return array Additional images size data.
40
	 */
41
	function wp_get_additional_image_sizes() {
42
		global $_wp_additional_image_sizes;
43
		if ( ! $_wp_additional_image_sizes ) {
44
			$_wp_additional_image_sizes = [];
45
		}
46
47
		return $_wp_additional_image_sizes;
48
	}
49
}
50