Code Duplication    Length = 33-33 lines in 2 locations

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

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