Code Duplication    Length = 33-33 lines in 2 locations

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

@@ 779-811 (lines=33) @@
776
		return 1; // The number of actions enqueued
777
	}
778
779
	private function maybe_sync_constants() {
780
		if ( get_transient( self::CONSTANTS_AWAIT_TRANSIENT_NAME ) ) {
781
			return;
782
		}
783
784
		$constants = $this->get_all_constants();
785
		if ( empty( $constants ) ) {
786
			return;
787
		}
788
789
		set_transient( self::CONSTANTS_AWAIT_TRANSIENT_NAME, microtime( true ), Jetpack_Sync_Defaults::$default_sync_constants_wait_time );
790
		$constants_checksums = get_option( self::CONSTANTS_CHECKSUM_OPTION_NAME, array() );
791
		// only send the constants that have changed
792
		foreach ( $constants as $name => $value ) {
793
			$checksum = $this->get_check_sum( $value );
794
795
			// explicitly not using Identical comparison as get_option returns a string
796
			if ( ! $this->still_valid_checksum( $constants_checksums, $name, $checksum ) ) {
797
				/**
798
				 * Tells the client to sync a constant to the server
799
				 *
800
				 * @since 4.2.0
801
				 *
802
				 * @param string The name of the constant
803
				 * @param mixed The value of the constant
804
				 */
805
				do_action( 'jetpack_sync_constant', $name, $value );
806
				$constants_checksums[ $name ] = $checksum;
807
			}
808
		}
809
810
		update_option( self::CONSTANTS_CHECKSUM_OPTION_NAME, $constants_checksums );
811
	}
812
	// public so that we don't have to store an option for each constant
813
	function get_all_constants() {
814
		return array_combine(
@@ 840-872 (lines=33) @@
837
		$this->maybe_sync_callables();
838
	}
839
840
	private function maybe_sync_callables() {
841
		if ( get_transient( self::CALLABLES_AWAIT_TRANSIENT_NAME ) ) {
842
			return;
843
		}
844
845
		$callables = $this->get_all_callables();
846
		if ( empty( $callables ) ) {
847
			return;
848
		}
849
850
		set_transient( self::CALLABLES_AWAIT_TRANSIENT_NAME, microtime( true ), Jetpack_Sync_Defaults::$default_sync_callables_wait_time );
851
852
		$callable_checksums = get_option( self::CALLABLES_CHECKSUM_OPTION_NAME , array() );
853
854
		// only send the callables that have changed
855
		foreach ( $callables as $name => $value ) {
856
			$checksum = $this->get_check_sum( $value );
857
			// explicitly not using Identical comparison as get_option returns a string
858
			if ( ! $this->still_valid_checksum( $callable_checksums, $name, $checksum ) ) {
859
				/**
860
				 * Tells the client to sync a callable (aka function) to the server
861
				 *
862
				 * @since 4.2.0
863
				 *
864
				 * @param string The name of the callable
865
				 * @param mixed The value of the callable
866
				 */
867
				do_action( 'jetpack_sync_callable', $name, $value );
868
				$callable_checksums[ $name ] = $checksum;
869
			}
870
		}
871
		update_option( self::CALLABLES_CHECKSUM_OPTION_NAME , $callable_checksums );
872
	}
873
874
	private function still_valid_checksum( $sums_to_check, $name, $new_sum ) {
875
		if ( isset( $sums_to_check[ $name ] ) && $sums_to_check[ $name ] === $new_sum ) {