Code Duplication    Length = 29-29 lines in 2 locations

functions.global.php 1 location

@@ 323-351 (lines=29) @@
320
 *
321
 * @return array
322
 */
323
function jetpack_json_wrap( &$any, $seen_nodes = array() ) {
324
	if ( is_object( $any ) ) {
325
		$input        = get_object_vars( $any );
326
		$input['__o'] = 1;
327
	} else {
328
		$input = &$any;
329
	}
330
331
	if ( is_array( $input ) ) {
332
		$seen_nodes[] = &$any;
333
334
		$return = array();
335
336
		foreach ( $input as $k => &$v ) {
337
			if ( ( is_array( $v ) || is_object( $v ) ) ) {
338
				if ( in_array( $v, $seen_nodes, true ) ) {
339
					continue;
340
				}
341
				$return[ $k ] = jetpack_json_wrap( $v, $seen_nodes );
342
			} else {
343
				$return[ $k ] = $v;
344
			}
345
		}
346
347
		return $return;
348
	}
349
350
	return $any;
351
}
352
353
/**
354
 * Checks if the mime_content_type function is available and return it if so.

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

@@ 81-109 (lines=29) @@
78
	 * @param array        $seen_nodes Seen nodes.
79
	 * @return array
80
	 */
81
	private function json_wrap( &$any, $seen_nodes = array() ) {
82
		if ( is_object( $any ) ) {
83
			$input        = get_object_vars( $any );
84
			$input['__o'] = 1;
85
		} else {
86
			$input = &$any;
87
		}
88
89
		if ( is_array( $input ) ) {
90
			$seen_nodes[] = &$any;
91
92
			$return = array();
93
94
			foreach ( $input as $k => &$v ) {
95
				if ( ( is_array( $v ) || is_object( $v ) ) ) {
96
					if ( in_array( $v, $seen_nodes, true ) ) {
97
						continue;
98
					}
99
					$return[ $k ] = $this->json_wrap( $v, $seen_nodes );
100
				} else {
101
					$return[ $k ] = $v;
102
				}
103
			}
104
105
			return $return;
106
		}
107
108
		return $any;
109
	}
110
111
	/**
112
	 * Unwraps a json_decode return.