Code Duplication    Length = 32-33 lines in 2 locations

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

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

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

@@ 6348-6379 (lines=32) @@
6345
	 * @param array $response
6346
	 * @return array Array of the local urls, wpcom urls, and error code
6347
	 */
6348
	public static function get_sync_error_idc_option( $response = array() ) {
6349
		// Since the local options will hit the database directly, store the values
6350
		// in a transient to allow for autoloading and caching on subsequent views.
6351
		$local_options = get_transient( 'jetpack_idc_local' );
6352
		if ( false === $local_options ) {
6353
			$local_options = array(
6354
				'home'    => Functions::home_url(),
6355
				'siteurl' => Functions::site_url(),
6356
			);
6357
			set_transient( 'jetpack_idc_local', $local_options, MINUTE_IN_SECONDS );
6358
		}
6359
6360
		$options = array_merge( $local_options, $response );
6361
6362
		$returned_values = array();
6363
		foreach ( $options as $key => $option ) {
6364
			if ( 'error_code' === $key ) {
6365
				$returned_values[ $key ] = $option;
6366
				continue;
6367
			}
6368
6369
			if ( is_wp_error( $normalized_url = self::normalize_url_protocol_agnostic( $option ) ) ) {
6370
				continue;
6371
			}
6372
6373
			$returned_values[ $key ] = $normalized_url;
6374
		}
6375
6376
		set_transient( 'jetpack_idc_option', $returned_values, MINUTE_IN_SECONDS );
6377
6378
		return $returned_values;
6379
	}
6380
6381
	/**
6382
	 * Returns the value of the jetpack_sync_idc_optin filter, or constant.