Code Duplication    Length = 33-33 lines in 2 locations

sync/class.jetpack-sync-client.php 2 locations

@@ 715-747 (lines=33) @@
712
		return 1; // The number of actions enqueued
713
	}
714
715
	private function maybe_sync_constants() {
716
		if ( get_transient( self::CONSTANTS_AWAIT_TRANSIENT_NAME ) ) {
717
			return;
718
		}
719
720
		$constants = $this->get_all_constants();
721
		if ( empty( $constants ) ) {
722
			return;
723
		}
724
725
		set_transient( self::CONSTANTS_AWAIT_TRANSIENT_NAME, microtime( true ), Jetpack_Sync_Defaults::$default_sync_constants_wait_time );
726
		$constants_checksums = get_option( self::CONSTANTS_CHECKSUM_OPTION_NAME, array() );
727
		// only send the constants that have changed
728
		foreach ( $constants as $name => $value ) {
729
			$checksum = $this->get_check_sum( $value );
730
731
			// explicitly not using Identical comparison as get_option returns a string
732
			if ( ! $this->still_valid_checksum( $constants_checksums, $name, $checksum ) ) {
733
				/**
734
				 * Tells the client to sync a constant to the server
735
				 *
736
				 * @since 4.2.0
737
				 *
738
				 * @param string The name of the constant
739
				 * @param mixed The value of the constant
740
				 */
741
				do_action( 'jetpack_sync_constant', $name, $value );
742
				$constants_checksums[ $name ] = $checksum;
743
			}
744
		}
745
746
		update_option( self::CONSTANTS_CHECKSUM_OPTION_NAME, $constants_checksums );
747
	}
748
	// public so that we don't have to store an option for each constant
749
	function get_all_constants() {
750
		return array_combine(
@@ 776-808 (lines=33) @@
773
		$this->maybe_sync_callables();
774
	}
775
776
	private function maybe_sync_callables() {
777
		if ( get_transient( self::CALLABLES_AWAIT_TRANSIENT_NAME ) ) {
778
			return;
779
		}
780
781
		$callables = $this->get_all_callables();
782
		if ( empty( $callables ) ) {
783
			return;
784
		}
785
786
		set_transient( self::CALLABLES_AWAIT_TRANSIENT_NAME, microtime( true ), Jetpack_Sync_Defaults::$default_sync_callables_wait_time );
787
788
		$callable_checksums = get_option( self::CALLABLES_CHECKSUM_OPTION_NAME , array() );
789
790
		// only send the callables that have changed
791
		foreach ( $callables as $name => $value ) {
792
			$checksum = $this->get_check_sum( $value );
793
			// explicitly not using Identical comparison as get_option returns a string
794
			if ( ! $this->still_valid_checksum( $callable_checksums, $name, $checksum ) ) {
795
				/**
796
				 * Tells the client to sync a callable (aka function) to the server
797
				 *
798
				 * @since 4.2.0
799
				 *
800
				 * @param string The name of the callable
801
				 * @param mixed The value of the callable
802
				 */
803
				do_action( 'jetpack_sync_callable', $name, $value );
804
				$callable_checksums[ $name ] = $checksum;
805
			}
806
		}
807
		update_option( self::CALLABLES_CHECKSUM_OPTION_NAME , $callable_checksums );
808
	}
809
810
	private function still_valid_checksum( $sums_to_check, $name, $new_sum ) {
811
		if ( isset( $sums_to_check[ $name ] ) && $sums_to_check[ $name ] === $new_sum ) {