Code Duplication    Length = 41-42 lines in 2 locations

projects/packages/identity-crisis/src/class-identity-crisis.php 1 location

@@ 268-308 (lines=41) @@
265
	 *
266
	 * @since 4.4.0
267
	 */
268
	public static function validate_sync_error_idc_option() {
269
		$is_valid = false;
270
271
		// Is the site opted in and does the stored sync_error_idc option match what we now generate?
272
		$sync_error = Jetpack_Options::get_option( 'sync_error_idc' );
273
		if ( $sync_error && self::sync_idc_optin() ) {
274
			$local_options = self::get_sync_error_idc_option();
275
			// Ensure all values are set.
276
			if ( isset( $sync_error['home'] ) && isset( $local_options['home'] ) && isset( $sync_error['siteurl'] ) && isset( $local_options['siteurl'] ) ) {
277
				// If the WP.com expected home and siteurl match local home and siteurl it is not valid IDC.
278
				if (
279
					isset( $sync_error['wpcom_home'] ) &&
280
					isset( $sync_error['wpcom_siteurl'] ) &&
281
					$sync_error['wpcom_home'] === $local_options['home'] &&
282
					$sync_error['wpcom_siteurl'] === $local_options['siteurl']
283
				) {
284
					$is_valid = false;
285
					// Enable migrate_for_idc so that sync actions are accepted.
286
					Jetpack_Options::update_option( 'migrate_for_idc', true );
287
				} elseif ( $sync_error['home'] === $local_options['home'] && $sync_error['siteurl'] === $local_options['siteurl'] ) {
288
					$is_valid = true;
289
				}
290
			}
291
		}
292
293
		/**
294
		 * Filters whether the sync_error_idc option is valid.
295
		 *
296
		 * @param bool $is_valid If the sync_error_idc is valid or not.
297
		 *
298
		 * @since 4.4.0
299
		 */
300
		$is_valid = (bool) apply_filters( 'jetpack_sync_error_idc_validation', $is_valid );
301
302
		if ( ! $is_valid && $sync_error ) {
303
			// Since the option exists, and did not validate, delete it.
304
			Jetpack_Options::delete_option( 'sync_error_idc' );
305
		}
306
307
		return $is_valid;
308
	}
309
310
	/**
311
	 * Normalizes a url by doing three things:

projects/plugins/jetpack/class.jetpack.php 1 location

@@ 6218-6259 (lines=42) @@
6215
	 *
6216
	 * @return bool
6217
	 */
6218
	public static function validate_sync_error_idc_option() {
6219
		$is_valid = false;
6220
6221
		// Is the site opted in and does the stored sync_error_idc option match what we now generate?
6222
		$sync_error = Jetpack_Options::get_option( 'sync_error_idc' );
6223
		if ( $sync_error && self::sync_idc_optin() ) {
6224
			$local_options = self::get_sync_error_idc_option();
6225
			// Ensure all values are set.
6226
			if ( isset( $sync_error['home'] ) && isset( $local_options['home'] ) && isset( $sync_error['siteurl'] ) && isset( $local_options['siteurl'] ) ) {
6227
6228
				// If the WP.com expected home and siteurl match local home and siteurl it is not valid IDC.
6229
				if (
6230
						isset( $sync_error['wpcom_home'] ) &&
6231
						isset( $sync_error['wpcom_siteurl'] ) &&
6232
						$sync_error['wpcom_home'] === $local_options['home'] &&
6233
						$sync_error['wpcom_siteurl'] === $local_options['siteurl']
6234
				) {
6235
					$is_valid = false;
6236
					// Enable migrate_for_idc so that sync actions are accepted.
6237
					Jetpack_Options::update_option( 'migrate_for_idc', true );
6238
				} elseif ( $sync_error['home'] === $local_options['home'] && $sync_error['siteurl'] === $local_options['siteurl'] ) {
6239
					$is_valid = true;
6240
				}
6241
			}
6242
		}
6243
6244
		/**
6245
		 * Filters whether the sync_error_idc option is valid.
6246
		 *
6247
		 * @since 4.4.0
6248
		 *
6249
		 * @param bool $is_valid If the sync_error_idc is valid or not.
6250
		 */
6251
		$is_valid = (bool) apply_filters( 'jetpack_sync_error_idc_validation', $is_valid );
6252
6253
		if ( ! $is_valid && $sync_error ) {
6254
			// Since the option exists, and did not validate, delete it
6255
			Jetpack_Options::delete_option( 'sync_error_idc' );
6256
		}
6257
6258
		return $is_valid;
6259
	}
6260
6261
	/**
6262
	 * Normalizes a url by doing three things: