Code Duplication    Length = 35-36 lines in 2 locations

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

@@ 792-826 (lines=35) @@
789
		return 1; // The number of actions enqueued
790
	}
791
792
	private function maybe_sync_constants() {
793
		if ( get_transient( self::CONSTANTS_AWAIT_TRANSIENT_NAME ) ) {
794
			return;
795
		}
796
797
		$constants = $this->get_all_constants();
798
		if ( empty( $constants ) ) {
799
			return;
800
		}
801
802
		set_transient( self::CONSTANTS_AWAIT_TRANSIENT_NAME, microtime( true ), Jetpack_Sync_Defaults::$default_sync_constants_wait_time );
803
		$constants_checksums = (array) get_option( self::CONSTANTS_CHECKSUM_OPTION_NAME, array() );
804
805
		foreach ( $constants as $name => $value ) {
806
			$checksum = $this->get_check_sum( $value );
807
			// explicitly not using Identical comparison as get_option returns a string
808
			if ( ! $this->still_valid_checksum( $constants_checksums, $name, $checksum )  && ! is_null( $value ) ) {
809
				/**
810
				 * Tells the client to sync a constant to the server
811
				 *
812
				 * @since 4.2.0
813
				 *
814
				 * @param string The name of the constant
815
				 * @param mixed The value of the constant
816
				 */
817
				do_action( 'jetpack_sync_constant', $name, $value );
818
				$constants_checksums[ $name ] = $checksum;
819
			} else {
820
				$constants_checksums[ $name ] = $checksum;
821
			}
822
		}
823
		update_option( self::CONSTANTS_CHECKSUM_OPTION_NAME, $constants_checksums );
824
	}
825
	// public so that we don't have to store an option for each constant
826
	function get_all_constants() {
827
		return array_combine(
828
			$this->constants_whitelist,
829
			array_map( array( $this, 'get_constant' ), $this->constants_whitelist )
@@ 853-888 (lines=36) @@
850
		$this->maybe_sync_callables();
851
	}
852
853
	private function maybe_sync_callables() {
854
		if ( get_transient( self::CALLABLES_AWAIT_TRANSIENT_NAME ) ) {
855
			return;
856
		}
857
		$callables = $this->get_all_callables();
858
		
859
		if ( empty( $callables ) ) {
860
			return;
861
		}
862
863
		set_transient( self::CALLABLES_AWAIT_TRANSIENT_NAME, microtime( true ), Jetpack_Sync_Defaults::$default_sync_callables_wait_time );
864
865
		$callable_checksums = (array) get_option( self::CALLABLES_CHECKSUM_OPTION_NAME , array() );
866
867
		// only send the callables that have changed
868
		foreach ( $callables as $name => $value ) {
869
			$checksum = $this->get_check_sum( $value );
870
			// explicitly not using Identical comparison as get_option returns a string
871
			if ( ! $this->still_valid_checksum( $callable_checksums, $name, $checksum ) && ! is_null( $value ) ) {
872
				/**
873
				 * Tells the client to sync a callable (aka function) to the server
874
				 *
875
				 * @since 4.2.0
876
				 *
877
				 * @param string The name of the callable
878
				 * @param mixed The value of the callable
879
				 */
880
				do_action( 'jetpack_sync_callable', $name, $value );
881
				$callable_checksums[ $name ] = $checksum;
882
			} else {
883
				$callable_checksums[ $name ] = $checksum;
884
			}
885
		}
886
		update_option( self::CALLABLES_CHECKSUM_OPTION_NAME , $callable_checksums );
887
	}
888
889
	private function still_valid_checksum( $sums_to_check, $name, $new_sum ) {
890
		if ( isset( $sums_to_check[ $name ] ) && $sums_to_check[ $name ] === $new_sum ) {
891
			return true;