Code Duplication    Length = 32-33 lines in 2 locations

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

@@ 349-381 (lines=33) @@
346
	 * @since 4.4.0
347
	 * @since 5.4.0 Add transient since home/siteurl retrieved directly from DB.
348
	 */
349
	public static function get_sync_error_idc_option( $response = array() ) {
350
		// Since the local options will hit the database directly, store the values
351
		// in a transient to allow for autoloading and caching on subsequent views.
352
		$local_options = get_transient( 'jetpack_idc_local' );
353
		if ( false === $local_options ) {
354
			$local_options = array(
355
				'home'    => Functions::home_url(),
356
				'siteurl' => Functions::site_url(),
357
			);
358
			set_transient( 'jetpack_idc_local', $local_options, MINUTE_IN_SECONDS );
359
		}
360
361
		$options = array_merge( $local_options, $response );
362
363
		$returned_values = array();
364
		foreach ( $options as $key => $option ) {
365
			if ( 'error_code' === $key ) {
366
				$returned_values[ $key ] = $option;
367
				continue;
368
			}
369
370
			$normalized_url = self::normalize_url_protocol_agnostic( $option );
371
			if ( is_wp_error( $normalized_url ) ) {
372
				continue;
373
			}
374
375
			$returned_values[ $key ] = $normalized_url;
376
		}
377
378
		set_transient( 'jetpack_idc_option', $returned_values, MINUTE_IN_SECONDS );
379
380
		return $returned_values;
381
	}
382
383
	/**
384
	 * Returns the value of the jetpack_sync_idc_optin filter, or constant.

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

@@ 6290-6321 (lines=32) @@
6287
	 * @param array $response
6288
	 * @return array Array of the local urls, wpcom urls, and error code
6289
	 */
6290
	public static function get_sync_error_idc_option( $response = array() ) {
6291
		// Since the local options will hit the database directly, store the values
6292
		// in a transient to allow for autoloading and caching on subsequent views.
6293
		$local_options = get_transient( 'jetpack_idc_local' );
6294
		if ( false === $local_options ) {
6295
			$local_options = array(
6296
				'home'    => Functions::home_url(),
6297
				'siteurl' => Functions::site_url(),
6298
			);
6299
			set_transient( 'jetpack_idc_local', $local_options, MINUTE_IN_SECONDS );
6300
		}
6301
6302
		$options = array_merge( $local_options, $response );
6303
6304
		$returned_values = array();
6305
		foreach ( $options as $key => $option ) {
6306
			if ( 'error_code' === $key ) {
6307
				$returned_values[ $key ] = $option;
6308
				continue;
6309
			}
6310
6311
			if ( is_wp_error( $normalized_url = self::normalize_url_protocol_agnostic( $option ) ) ) {
6312
				continue;
6313
			}
6314
6315
			$returned_values[ $key ] = $normalized_url;
6316
		}
6317
6318
		set_transient( 'jetpack_idc_option', $returned_values, MINUTE_IN_SECONDS );
6319
6320
		return $returned_values;
6321
	}
6322
6323
	/**
6324
	 * Returns the value of the jetpack_sync_idc_optin filter, or constant.