Code Duplication    Length = 33-33 lines in 2 locations

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

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