Code Duplication    Length = 18-19 lines in 2 locations

modules/perf/class.jetpack-perf-optimize-assets.php 2 locations

@@ 256-274 (lines=19) @@
253
		return $tag;
254
	}
255
256
	private function should_async_script( $script ) {
257
		global $wp_scripts;
258
259
		// explicitly in the header (scripts aren't affected much by async)
260
		$should_async_script = $script->args === 0;
261
262
		// only make scripts async if nothing depends on them
263
		foreach ( $wp_scripts->to_do as $other_script_handle ) {
264
			$other_script = $wp_scripts->registered[ $other_script_handle ];
265
			if ( in_array( $script->handle, $other_script->deps ) ) {
266
				$should_async_script = false;
267
				break;
268
			}
269
		}
270
271
		// you can override this logic by setting jetpack-async
272
		$should_async_script = $should_async_script || ( isset( $script->extra['jetpack-async'] ) && $script->extra['jetpack-async'] );
273
		return $this->async_scripts && apply_filters( 'jetpack_perf_async_script', $should_async_script, $script->handle, $script->src );
274
	}
275
276
	private function should_defer_script( $script ) {
277
		global $wp_scripts;
@@ 276-293 (lines=18) @@
273
		return $this->async_scripts && apply_filters( 'jetpack_perf_async_script', $should_async_script, $script->handle, $script->src );
274
	}
275
276
	private function should_defer_script( $script ) {
277
		global $wp_scripts;
278
279
		// if it's explicitly not in the footer, or we have Jetpack Defer set, and has no dependencies
280
		$should_defer_script = $script->args === 0;
281
282
		// only make scripts deferred if nothing depends on them
283
		foreach ( $wp_scripts->to_do as $other_script_handle ) {
284
			$other_script = $wp_scripts->registered[ $other_script_handle ];
285
			if ( in_array( $script->handle, $other_script->deps ) ) {
286
				$should_defer_script = false;
287
				break;
288
			}
289
		}
290
291
		$should_defer_script = $should_defer_script || ( isset( $script->extra['jetpack-defer'] ) && $script->extra['jetpack-defer'] );
292
		return $this->defer_scripts && apply_filters( 'jetpack_perf_defer_script', $should_defer_script, $script->handle, $script->src );
293
	}
294
295
	private function should_remove_script( $script ) {
296
		return $this->should_remove_asset( 'jetpack_perf_remove_script', $script );