Code Duplication    Length = 28-29 lines in 2 locations

sync/class.jetpack-sync-json-deflate-array-codec.php 1 location

@@ 33-61 (lines=29) @@
30
		return $this->json_unwrap( json_decode( $str, true ) );
31
	}
32
33
	private function json_wrap( &$any, $seen_nodes = array() ) {
34
		if ( is_object( $any ) ) {
35
			$input = get_object_vars( $any );
36
			$input['__o'] = 1;
37
		} else {
38
			$input = &$any;
39
		}
40
41
		if ( is_array( $input ) ) {
42
			$seen_nodes[] = &$any;
43
44
			$return = array();
45
46
			foreach ( $input as $k => &$v ) {
47
				if ( ( is_array( $v ) || is_object( $v ) ) ) {
48
					if ( in_array( $v, $seen_nodes, true ) ) {
49
						continue;
50
					} 
51
					$return[ $k ] = $this->json_wrap( $v, $seen_nodes );
52
				} else {
53
					$return[ $k ] = $v;	
54
				}
55
			}
56
57
			return $return;
58
		}
59
60
		return $any;
61
	}
62
63
	private function json_unwrap( $any ) {
64
		if ( is_array( $any ) ) {

sync/class.jetpack-sync-module.php 1 location

@@ 53-80 (lines=28) @@
50
		return crc32( wp_json_encode( $this->json_encode( $values ) ) );
51
	}
52
53
	private function json_encode( &$any, $seen_nodes = array() ) {
54
		if ( is_object( $any ) ) {
55
			$input = get_object_vars( $any );
56
		} else {
57
			$input = &$any;
58
		}
59
60
		if ( is_array( $input ) ) {
61
			$seen_nodes[] = &$any;
62
63
			$return = array();
64
65
			foreach ( $input as $k => &$v ) {
66
				if ( ( is_array( $v ) || is_object( $v ) ) ) {
67
					if ( in_array( $v, $seen_nodes, true ) ) {
68
						continue;
69
					}
70
					$return[ $k ] = $this->json_encode( $v, $seen_nodes );
71
				} else {
72
					$return[ $k ] = $v;
73
				}
74
			}
75
76
			return $return;
77
		}
78
79
		return $any;
80
	}
81
82
	protected function still_valid_checksum( $sums_to_check, $name, $new_sum ) {
83
		if ( isset( $sums_to_check[ $name ] ) && $sums_to_check[ $name ] === $new_sum ) {