Code Duplication    Length = 29-29 lines in 2 locations

packages/sync/src/Json_Deflate_Array_Codec.php 1 location

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

functions.global.php 1 location

@@ 234-262 (lines=29) @@
231
 *
232
 * @return array
233
 */
234
function jetpack_json_wrap( &$any, $seen_nodes = array() ) {
235
	if ( is_object( $any ) ) {
236
		$input        = get_object_vars( $any );
237
		$input['__o'] = 1;
238
	} else {
239
		$input = &$any;
240
	}
241
242
	if ( is_array( $input ) ) {
243
		$seen_nodes[] = &$any;
244
245
		$return = array();
246
247
		foreach ( $input as $k => &$v ) {
248
			if ( ( is_array( $v ) || is_object( $v ) ) ) {
249
				if ( in_array( $v, $seen_nodes, true ) ) {
250
					continue;
251
				}
252
				$return[ $k ] = jetpack_json_wrap( $v, $seen_nodes );
253
			} else {
254
				$return[ $k ] = $v;
255
			}
256
		}
257
258
		return $return;
259
	}
260
261
	return $any;
262
}
263
264
/**
265
 * Checks if the mime_content_type function is available and return it if so.