Code Duplication    Length = 18-19 lines in 2 locations

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

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