Code Duplication    Length = 33-33 lines in 2 locations

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

@@ 788-820 (lines=33) @@
785
		$this->maybe_sync_callables();
786
	}
787
788
	private function maybe_sync_callables() {
789
		if ( get_transient( self::CALLABLES_AWAIT_TRANSIENT_NAME ) ) {
790
			return;
791
		}
792
793
		$callables = $this->get_all_callables();
794
		if ( empty( $callables ) ) {
795
			return;
796
		}
797
798
		set_transient( self::CALLABLES_AWAIT_TRANSIENT_NAME, microtime( true ), Jetpack_Sync_Defaults::$default_sync_callables_wait_time );
799
800
		$callable_checksums = get_option( self::CALLABLES_CHECKSUM_OPTION_NAME , array() );
801
802
		// only send the callables that have changed
803
		foreach ( $callables as $name => $value ) {
804
			$checksum = $this->get_check_sum( $value );
805
			// explicitly not using Identical comparison as get_option returns a string
806
			if ( ! $this->still_valid_checksum( $callable_checksums, $name, $checksum ) ) {
807
				/**
808
				 * Tells the client to sync a callable (aka function) to the server
809
				 *
810
				 * @since 4.2.0
811
				 *
812
				 * @param string The name of the callable
813
				 * @param mixed The value of the callable
814
				 */
815
				do_action( 'jetpack_sync_callable', $name, $value );
816
				$callable_checksums[ $name ] = $checksum;
817
			}
818
		}
819
		update_option( self::CALLABLES_CHECKSUM_OPTION_NAME , $callable_checksums );
820
	}
821
822
	private function still_valid_checksum( $sums_to_check, $name, $new_sum ) {
823
		if ( isset( $sums_to_check[ $name ] ) && $sums_to_check[ $name ] === $new_sum ) {
@@ 727-759 (lines=33) @@
724
		return 1; // The number of actions enqueued
725
	}
726
727
	private function maybe_sync_constants() {
728
		if ( get_transient( self::CONSTANTS_AWAIT_TRANSIENT_NAME ) ) {
729
			return;
730
		}
731
732
		$constants = $this->get_all_constants();
733
		if ( empty( $constants ) ) {
734
			return;
735
		}
736
737
		set_transient( self::CONSTANTS_AWAIT_TRANSIENT_NAME, microtime( true ), Jetpack_Sync_Defaults::$default_sync_constants_wait_time );
738
		$constants_checksums = get_option( self::CONSTANTS_CHECKSUM_OPTION_NAME, array() );
739
		// only send the constants that have changed
740
		foreach ( $constants as $name => $value ) {
741
			$checksum = $this->get_check_sum( $value );
742
743
			// explicitly not using Identical comparison as get_option returns a string
744
			if ( ! $this->still_valid_checksum( $constants_checksums, $name, $checksum ) ) {
745
				/**
746
				 * Tells the client to sync a constant to the server
747
				 *
748
				 * @since 4.2.0
749
				 *
750
				 * @param string The name of the constant
751
				 * @param mixed The value of the constant
752
				 */
753
				do_action( 'jetpack_sync_constant', $name, $value );
754
				$constants_checksums[ $name ] = $checksum;
755
			}
756
		}
757
758
		update_option( self::CONSTANTS_CHECKSUM_OPTION_NAME, $constants_checksums );
759
	}
760
	// public so that we don't have to store an option for each constant
761
	function get_all_constants() {
762
		return array_combine(