Code Duplication    Length = 23-23 lines in 2 locations

modules/asset-cdn/asset-cdn.php 2 locations

@@ 81-103 (lines=23) @@
78
	 * so they're still served from the CDN
79
	 */
80
81
	function rewrite_script_src( $src, $handle ) {
82
		global $wp_scripts;
83
84
		if ( is_admin() || ! isset( $wp_scripts->registered[$handle] ) ) {
85
			return $src;
86
		}
87
88
		$script = $wp_scripts->registered[$handle];
89
90
		if ( ! $this->should_concat_script( $script ) && $this->should_cdn_script( $script ) ) {
91
			// serve this script from the CDN
92
			$parts = parse_url( $src );
93
			$url = $this->cdn_server . '/js';
94
			$url = add_query_arg( array(
95
				'b' => "{$parts['scheme']}://{$parts['host']}",
96
				'f' => array( $parts['path'] ),
97
				'v' => array( $script->ver )
98
			), $url );
99
			return $url;
100
		}
101
102
		return $src;
103
	}
104
105
	function should_cdn_script( $script ) {
106
		$should_cdn = ( $this->include_external_assets || $this->is_local_url( $script->src ) );
@@ 110-132 (lines=23) @@
107
		return apply_filters( 'jetpack_perf_cdn_script', $should_cdn, $script->handle, $script->src );
108
	}
109
110
	function rewrite_style_src( $src, $handle ) {
111
		global $wp_styles;
112
113
		if ( is_admin() || ! isset( $wp_styles->registered[$handle] ) ) {
114
			return $src;
115
		}
116
117
		$style = $wp_styles->registered[$handle];
118
119
		if ( ! $this->should_concat_style( $style ) && $this->should_cdn_style( $style ) ) {
120
			// serve this style from the CDN
121
			$parts = parse_url( $src );
122
			$url = $this->cdn_server . '/js';
123
			$url = add_query_arg( array(
124
				'b' => "{$parts['scheme']}://{$parts['host']}",
125
				'f' => array( $parts['path'] ),
126
				'v' => array( $style->ver )
127
			), $url );
128
			return $url;
129
		}
130
131
		return $src;
132
	}
133
134
	function should_cdn_style( $style ) {
135
		$should_cdn = ( $this->include_external_assets || $this->is_local_url( $style->src ) );