Code Duplication    Length = 33-33 lines in 2 locations

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

@@ 751-783 (lines=33) @@
748
		return 1; // The number of actions enqueued
749
	}
750
751
	private function maybe_sync_constants() {
752
		if ( get_transient( self::CONSTANTS_AWAIT_TRANSIENT_NAME ) ) {
753
			return;
754
		}
755
756
		$constants = $this->get_all_constants();
757
		if ( empty( $constants ) ) {
758
			return;
759
		}
760
761
		set_transient( self::CONSTANTS_AWAIT_TRANSIENT_NAME, microtime( true ), Jetpack_Sync_Defaults::$default_sync_constants_wait_time );
762
		$constants_checksums = get_option( self::CONSTANTS_CHECKSUM_OPTION_NAME, array() );
763
		// only send the constants that have changed
764
		foreach ( $constants as $name => $value ) {
765
			$checksum = $this->get_check_sum( $value );
766
767
			// explicitly not using Identical comparison as get_option returns a string
768
			if ( ! $this->still_valid_checksum( $constants_checksums, $name, $checksum ) ) {
769
				/**
770
				 * Tells the client to sync a constant to the server
771
				 *
772
				 * @since 4.2.0
773
				 *
774
				 * @param string The name of the constant
775
				 * @param mixed The value of the constant
776
				 */
777
				do_action( 'jetpack_sync_constant', $name, $value );
778
				$constants_checksums[ $name ] = $checksum;
779
			}
780
		}
781
782
		update_option( self::CONSTANTS_CHECKSUM_OPTION_NAME, $constants_checksums );
783
	}
784
	// public so that we don't have to store an option for each constant
785
	function get_all_constants() {
786
		return array_combine(
@@ 812-844 (lines=33) @@
809
		$this->maybe_sync_callables();
810
	}
811
812
	private function maybe_sync_callables() {
813
		if ( get_transient( self::CALLABLES_AWAIT_TRANSIENT_NAME ) ) {
814
			return;
815
		}
816
817
		$callables = $this->get_all_callables();
818
		if ( empty( $callables ) ) {
819
			return;
820
		}
821
822
		set_transient( self::CALLABLES_AWAIT_TRANSIENT_NAME, microtime( true ), Jetpack_Sync_Defaults::$default_sync_callables_wait_time );
823
824
		$callable_checksums = get_option( self::CALLABLES_CHECKSUM_OPTION_NAME , array() );
825
826
		// only send the callables that have changed
827
		foreach ( $callables as $name => $value ) {
828
			$checksum = $this->get_check_sum( $value );
829
			// explicitly not using Identical comparison as get_option returns a string
830
			if ( ! $this->still_valid_checksum( $callable_checksums, $name, $checksum ) ) {
831
				/**
832
				 * Tells the client to sync a callable (aka function) to the server
833
				 *
834
				 * @since 4.2.0
835
				 *
836
				 * @param string The name of the callable
837
				 * @param mixed The value of the callable
838
				 */
839
				do_action( 'jetpack_sync_callable', $name, $value );
840
				$callable_checksums[ $name ] = $checksum;
841
			}
842
		}
843
		update_option( self::CALLABLES_CHECKSUM_OPTION_NAME , $callable_checksums );
844
	}
845
846
	private function still_valid_checksum( $sums_to_check, $name, $new_sum ) {
847
		if ( isset( $sums_to_check[ $name ] ) && $sums_to_check[ $name ] === $new_sum ) {