Completed
Push — update/add-single-purpose-jetp... ( 28d890...705f7e )
by
unknown
09:19
created

Utils::fix_url_for_bad_hosts()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
nc 3
nop 1
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
1
<?php
2
/**
3
 * The Jetpack Connection package Utils class file.
4
 *
5
 * @package automattic/jetpack-connection
6
 */
7
8
namespace Automattic\Jetpack\Connection;
9
10
use Automattic\Jetpack\Constants;
11
12
/**
13
 * Provides utility methods for the Connection package.
14
 */
15
class Utils {
16
17
	/**
18
	 * Some hosts disable the OpenSSL extension and so cannot make outgoing HTTPS requests.
19
	 * This method sets the URL scheme to HTTP when HTTPS requests can't be made.
20
	 *
21
	 * @param String $url The url.
22
	 * @return String The url with the required URL scheme.
23
	 */
24
	public static function fix_url_for_bad_hosts( $url ) {
25
		// If we receive an http url, return it.
26
		if ( 'http' === wp_parse_url( $url, PHP_URL_SCHEME ) ) {
27
			return $url;
28
		}
29
30
		// If the url should never be https, ensure it isn't https.
31
		if ( 'NEVER' === Constants::get_constant( 'JETPACK_CLIENT__HTTPS' ) ) {
32
			return set_url_scheme( $url, 'http' );
33
		}
34
35
		// Otherwise, return the https url.
36
		return $url;
37
	}
38
}
39