Code Duplication    Length = 41-42 lines in 2 locations

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

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

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

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