Code Duplication    Length = 29-29 lines in 2 locations

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

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

functions.global.php 1 location

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