Completed
Pull Request — master (#16)
by Rasmus
04:25
created

compability.php ➔ wp_parse_url()   C

Complexity

Conditions 8
Paths 8

Size

Total Lines 29
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
eloc 17
nc 8
nop 1
dl 0
loc 29
rs 5.3846
c 0
b 0
f 0
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