Passed
Push — master ( c00bbb...af6e37 )
by Brian
04:11
created
includes/data/vat-number-regexes.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@
 block discarded – undo
6 6
  * @package Invoicing/data
7 7
  */
8 8
 
9
-defined( 'ABSPATH' ) || exit;
9
+defined('ABSPATH') || exit;
10 10
 
11 11
 return array(
12 12
 
Please login to merge, or discard this patch.
includes/geolocation/class-getpaid-geolocation.php 1 patch
Spacing   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  *
7 7
  */
8 8
 
9
-defined( 'ABSPATH' ) || exit;
9
+defined('ABSPATH') || exit;
10 10
 
11 11
 /**
12 12
  * GetPaid_Geolocation Class.
@@ -64,31 +64,31 @@  discard block
 block discarded – undo
64 64
 
65 65
 		$transient_name = 'external_ip_address_0.0.0.0';
66 66
 
67
-		if ( '' !== self::get_ip_address() ) {
68
-			$transient_name      = 'external_ip_address_' . self::get_ip_address();
67
+		if ('' !== self::get_ip_address()) {
68
+			$transient_name = 'external_ip_address_' . self::get_ip_address();
69 69
 		}
70 70
 
71 71
 		// Try retrieving from cache.
72
-		$external_ip_address = get_transient( $transient_name );
72
+		$external_ip_address = get_transient($transient_name);
73 73
 
74
-		if ( false === $external_ip_address ) {
74
+		if (false === $external_ip_address) {
75 75
 			$external_ip_address     = '0.0.0.0';
76
-			$ip_lookup_services      = apply_filters( 'getpaid_geolocation_ip_lookup_apis', self::$ip_lookup_apis );
77
-			$ip_lookup_services_keys = array_keys( $ip_lookup_services );
78
-			shuffle( $ip_lookup_services_keys );
76
+			$ip_lookup_services      = apply_filters('getpaid_geolocation_ip_lookup_apis', self::$ip_lookup_apis);
77
+			$ip_lookup_services_keys = array_keys($ip_lookup_services);
78
+			shuffle($ip_lookup_services_keys);
79 79
 
80
-			foreach ( $ip_lookup_services_keys as $service_name ) {
81
-				$service_endpoint = $ip_lookup_services[ $service_name ];
82
-				$response         = wp_safe_remote_get( $service_endpoint, array( 'timeout' => 2 ) );
80
+			foreach ($ip_lookup_services_keys as $service_name) {
81
+				$service_endpoint = $ip_lookup_services[$service_name];
82
+				$response         = wp_safe_remote_get($service_endpoint, array('timeout' => 2));
83 83
 
84
-				if ( ! is_wp_error( $response ) && rest_is_ip_address( $response['body'] ) ) {
85
-					$external_ip_address = apply_filters( 'getpaid_geolocation_ip_lookup_api_response', wpinv_clean( $response['body'] ), $service_name );
84
+				if (!is_wp_error($response) && rest_is_ip_address($response['body'])) {
85
+					$external_ip_address = apply_filters('getpaid_geolocation_ip_lookup_api_response', wpinv_clean($response['body']), $service_name);
86 86
 					break;
87 87
 				}
88 88
 
89 89
 			}
90 90
 
91
-			set_transient( $transient_name, $external_ip_address, WEEK_IN_SECONDS );
91
+			set_transient($transient_name, $external_ip_address, WEEK_IN_SECONDS);
92 92
 		}
93 93
 
94 94
 		return $external_ip_address;
@@ -102,9 +102,9 @@  discard block
 block discarded – undo
102 102
 	 * @param  bool   $api_fallback If true, uses geolocation APIs if the database file doesn't exist (can be slower).
103 103
 	 * @return array
104 104
 	 */
105
-	public static function geolocate_ip( $ip_address = '', $fallback = false, $api_fallback = true ) {
105
+	public static function geolocate_ip($ip_address = '', $fallback = false, $api_fallback = true) {
106 106
 
107
-		if ( empty( $ip_address ) ) {
107
+		if (empty($ip_address)) {
108 108
 			$ip_address = self::get_ip_address();
109 109
 		}
110 110
 
@@ -112,9 +112,9 @@  discard block
 block discarded – undo
112 112
 		self::$current_user_ip = $ip_address;
113 113
 
114 114
 		// Filter to allow custom geolocation of the IP address.
115
-		$country_code = apply_filters( 'getpaid_geolocate_ip', false, $ip_address, $fallback, $api_fallback );
115
+		$country_code = apply_filters('getpaid_geolocate_ip', false, $ip_address, $fallback, $api_fallback);
116 116
 
117
-		if ( false !== $country_code ) {
117
+		if (false !== $country_code) {
118 118
 
119 119
 			return array(
120 120
 				'country'  => $country_code,
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
 		 * @param array  $geolocation Geolocation data, including country, state, city, and postcode.
135 135
 		 * @param string $ip_address  IP Address.
136 136
 		 */
137
-		$geolocation  = apply_filters(
137
+		$geolocation = apply_filters(
138 138
 			'getpaid_get_geolocation',
139 139
 			array(
140 140
 				'country'  => $country_code,
@@ -146,18 +146,18 @@  discard block
 block discarded – undo
146 146
 		);
147 147
 
148 148
 		// If we still haven't found a country code, let's consider doing an API lookup.
149
-		if ( '' === $geolocation['country'] && $api_fallback ) {
150
-			$geolocation['country'] = self::geolocate_via_api( $ip_address );
149
+		if ('' === $geolocation['country'] && $api_fallback) {
150
+			$geolocation['country'] = self::geolocate_via_api($ip_address);
151 151
 		}
152 152
 
153 153
 		// It's possible that we're in a local environment, in which case the geolocation needs to be done from the
154 154
 		// external address.
155
-		if ( '' === $geolocation['country'] && $fallback ) {
155
+		if ('' === $geolocation['country'] && $fallback) {
156 156
 			$external_ip_address = self::get_external_ip_address();
157 157
 
158 158
 			// Only bother with this if the external IP differs.
159
-			if ( '0.0.0.0' !== $external_ip_address && $external_ip_address !== $ip_address ) {
160
-				return self::geolocate_ip( $external_ip_address, false, $api_fallback );
159
+			if ('0.0.0.0' !== $external_ip_address && $external_ip_address !== $ip_address) {
160
+				return self::geolocate_ip($external_ip_address, false, $api_fallback);
161 161
 			}
162 162
 
163 163
 		}
@@ -187,12 +187,12 @@  discard block
 block discarded – undo
187 187
 			'HTTP_X_COUNTRY_CODE',
188 188
 		);
189 189
 
190
-		foreach ( $headers as $header ) {
191
-			if ( empty( $_SERVER[ $header ] ) ) {
190
+		foreach ($headers as $header) {
191
+			if (empty($_SERVER[$header])) {
192 192
 				continue;
193 193
 			}
194 194
 
195
-			$country_code = strtoupper( sanitize_text_field( wp_unslash( $_SERVER[ $header ] ) ) );
195
+			$country_code = strtoupper(sanitize_text_field(wp_unslash($_SERVER[$header])));
196 196
 			break;
197 197
 		}
198 198
 
@@ -211,36 +211,36 @@  discard block
 block discarded – undo
211 211
 	 * @param  string $ip_address IP address.
212 212
 	 * @return string
213 213
 	 */
214
-	protected static function geolocate_via_api( $ip_address ) {
214
+	protected static function geolocate_via_api($ip_address) {
215 215
 
216 216
 		// Retrieve from cache...
217
-		$country_code = get_transient( 'geoip_' . $ip_address );
217
+		$country_code = get_transient('geoip_' . $ip_address);
218 218
 
219 219
 		// If missing, retrieve from the API.
220
-		if ( false === $country_code ) {
221
-			$geoip_services = apply_filters( 'getpaid_geolocation_geoip_apis', self::$geoip_apis );
220
+		if (false === $country_code) {
221
+			$geoip_services = apply_filters('getpaid_geolocation_geoip_apis', self::$geoip_apis);
222 222
 
223
-			if ( empty( $geoip_services ) ) {
223
+			if (empty($geoip_services)) {
224 224
 				return '';
225 225
 			}
226 226
 
227
-			$geoip_services_keys = array_keys( $geoip_services );
227
+			$geoip_services_keys = array_keys($geoip_services);
228 228
 
229
-			shuffle( $geoip_services_keys );
229
+			shuffle($geoip_services_keys);
230 230
 
231
-			foreach ( $geoip_services_keys as $service_name ) {
231
+			foreach ($geoip_services_keys as $service_name) {
232 232
 
233
-				$service_endpoint = $geoip_services[ $service_name ];
234
-				$response         = wp_safe_remote_get( sprintf( $service_endpoint, $ip_address ), array( 'timeout' => 2 ) );
235
-				$country_code     = sanitize_text_field( strtoupper( self::handle_geolocation_response( $response, $service_name ) ) );
233
+				$service_endpoint = $geoip_services[$service_name];
234
+				$response         = wp_safe_remote_get(sprintf($service_endpoint, $ip_address), array('timeout' => 2));
235
+				$country_code     = sanitize_text_field(strtoupper(self::handle_geolocation_response($response, $service_name)));
236 236
 
237
-				if ( ! empty( $country_code ) ) {
237
+				if (!empty($country_code)) {
238 238
 					break;
239 239
 				}
240 240
 
241 241
 			}
242 242
 
243
-			set_transient( 'geoip_' . $ip_address, $country_code, WEEK_IN_SECONDS );
243
+			set_transient('geoip_' . $ip_address, $country_code, WEEK_IN_SECONDS);
244 244
 		}
245 245
 
246 246
 		return $country_code;
@@ -253,23 +253,23 @@  discard block
 block discarded – undo
253 253
 	 * @param  String $geolocation_service
254 254
 	 * @return string Country code
255 255
 	 */
256
-	protected static function handle_geolocation_response( $geolocation_response, $geolocation_service ) {
256
+	protected static function handle_geolocation_response($geolocation_response, $geolocation_service) {
257 257
 
258
-		if ( is_wp_error( $geolocation_response ) || empty( $geolocation_response['body'] ) ) {
258
+		if (is_wp_error($geolocation_response) || empty($geolocation_response['body'])) {
259 259
 			return '';
260 260
 		}
261 261
 
262
-		if ( $geolocation_service === 'ipinfo.io' ) {
263
-			$data = json_decode( $geolocation_response['body'] );
264
-			return empty( $data ) || empty( $data->country ) ? '' : $data->country;
262
+		if ($geolocation_service === 'ipinfo.io') {
263
+			$data = json_decode($geolocation_response['body']);
264
+			return empty($data) || empty($data->country) ? '' : $data->country;
265 265
 		}
266 266
 
267
-		if ( $geolocation_service === 'ip-api.com' ) {
268
-			$data = json_decode( $geolocation_response['body'] );
269
-			return empty( $data ) || empty( $data->countryCode ) ? '' : $data->countryCode;
267
+		if ($geolocation_service === 'ip-api.com') {
268
+			$data = json_decode($geolocation_response['body']);
269
+			return empty($data) || empty($data->countryCode) ? '' : $data->countryCode;
270 270
 		}
271 271
 
272
-		return apply_filters( 'getpaid_geolocation_geoip_response_' . $geolocation_service, '', $geolocation_response['body'] );
272
+		return apply_filters('getpaid_geolocation_geoip_response_' . $geolocation_service, '', $geolocation_response['body']);
273 273
 
274 274
 	}
275 275
 
Please login to merge, or discard this patch.