Completed
Push — instant-search-master ( 8be3b4...336413 )
by
unknown
06:37 queued 10s
created

Jetpack_Site   C

Complexity

Total Complexity 54

Size/Duplication

Total Lines 238
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 7

Importance

Changes 0
Metric Value
dl 0
loc 238
rs 6.4799
c 0
b 0
f 0
wmc 54
lcom 0
cbo 7

45 Methods

Rating   Name   Duplication   Size   Complexity  
A get_mock_option() 0 3 1
A get_constant() 0 6 2
A main_network_site() 0 3 1
A wp_version() 0 4 1
A max_upload_size() 0 3 1
A wp_memory_limit() 0 3 1
A wp_max_memory_limit() 0 3 1
A is_main_network() 0 3 1
A is_multisite() 0 3 1
A is_single_user_site() 0 3 1
A is_version_controlled() 0 3 1
A file_system_write_access() 0 3 1
A current_theme_supports() 0 3 1
A get_theme_support() 0 3 1
A get_updates() 0 3 1
A get_id() 0 3 1
A has_videopress() 0 9 3
A upgraded_filetypes_enabled() 0 3 1
A is_mapped_domain() 0 3 1
A get_unmapped_url() 0 4 1
A is_redirect() 0 3 1
A is_following() 0 3 1
A has_wordads() 0 3 1
A get_frame_nonce() 0 3 1
A get_jetpack_frame_nonce() 0 3 1
A is_headstart_fresh() 0 3 1
A allowed_file_types() 0 14 3
A is_private() 0 3 1
A get_plan() 0 3 1
A get_subscribers_count() 0 3 1
A get_capabilities() 0 3 1
A get_locale() 0 3 1
A is_jetpack() 0 3 1
A get_jetpack_version() 0 3 1
A get_ak_vp_bundle_enabled() 0 1 1
A get_jetpack_seo_front_page_description() 0 3 1
A get_jetpack_seo_title_formats() 0 3 1
A get_verification_services_codes() 0 3 1
A get_podcasting_archive() 0 3 1
A is_connected_site() 0 3 1
A current_user_can() 0 3 1
A is_fse_active() 0 6 3
A is_fse_eligible() 0 6 3
A get_import_engine() 0 3 1
A wrap_post() 0 3 1

How to fix   Complexity   

Complex Class

Complex classes like Jetpack_Site often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use Jetpack_Site, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
use Automattic\Jetpack\Sync\Functions;
4
5
require_once dirname( __FILE__ ) . '/class.json-api-site-jetpack-base.php';
6
require_once dirname( __FILE__ ) . '/class.json-api-post-jetpack.php';
7
8
// this code runs on Jetpack (.org) sites
9
class Jetpack_Site extends Abstract_Jetpack_Site {
10
11
	protected function get_mock_option( $name ) {
12
		return get_option( 'jetpack_'.$name );
13
	}
14
15
	protected function get_constant( $name ) {
16
		if ( defined( $name) ) {
17
			return constant( $name );
18
		}
19
		return null;
20
	}
21
22
	protected function main_network_site() {
23
		return network_site_url();
24
	}
25
26
	protected function wp_version() {
27
		global $wp_version;
28
		return $wp_version;
29
	}
30
31
	protected function max_upload_size() {
32
		return wp_max_upload_size();
33
	}
34
35
	protected function wp_memory_limit() {
36
		return wp_convert_hr_to_bytes( WP_MEMORY_LIMIT );
37
	}
38
39
	protected function wp_max_memory_limit() {
40
		return wp_convert_hr_to_bytes( WP_MAX_MEMORY_LIMIT );
41
	}
42
43
	protected function is_main_network() {
44
		return Jetpack::is_multi_network();
45
	}
46
47
	public function is_multisite() {
48
		return (bool) is_multisite();
49
	}
50
51
	public function is_single_user_site() {
52
		return (bool) Jetpack::is_single_user_site();
53
	}
54
55
	protected function is_version_controlled() {
56
		return Functions::is_version_controlled();
57
	}
58
59
	protected function file_system_write_access() {
60
		return Functions::file_system_write_access();
61
	}
62
63
	protected function current_theme_supports( $feature_name ) {
64
		return current_theme_supports( $feature_name );
65
	}
66
67
	protected function get_theme_support( $feature_name ) {
68
		return get_theme_support( $feature_name );
69
	}
70
71
	public function get_updates() {
72
		return (array) Jetpack::get_updates();
73
	}
74
75
	function get_id() {
76
		return $this->platform->token->blog_id;
77
	}
78
79
	function has_videopress() {
80
		// TODO - this only works on wporg site - need to detect videopress option for remote Jetpack site on WPCOM
81
		$videopress = Jetpack_Options::get_option( 'videopress', array() );
82
		if ( isset( $videopress['blog_id'] ) && $videopress['blog_id'] > 0 ) {
83
			return true;
84
		}
85
86
		return false;
87
	}
88
89
	function upgraded_filetypes_enabled() {
90
		return true;
91
	}
92
93
	function is_mapped_domain() {
94
		return true;
95
	}
96
97
	function get_unmapped_url() {
98
		// Fallback to the home URL since all Jetpack sites don't have an unmapped *.wordpress.com domain.
99
		return $this->get_url();
100
	}
101
102
	function is_redirect() {
103
		return false;
104
	}
105
106
	function is_following() {
107
		return false;
108
	}
109
110
	function has_wordads() {
111
		return Jetpack::is_module_active( 'wordads' );
112
	}
113
114
	function get_frame_nonce() {
115
		return false;
116
	}
117
118
	function get_jetpack_frame_nonce() {
119
		return false;
120
	}
121
122
	function is_headstart_fresh() {
123
		return false;
124
	}
125
126
	function allowed_file_types() {
127
		$allowed_file_types = array();
128
129
		// https://codex.wordpress.org/Uploading_Files
130
		$mime_types = get_allowed_mime_types();
131
		foreach ( $mime_types as $type => $mime_type ) {
132
			$extras = explode( '|', $type );
133
			foreach ( $extras as $extra ) {
134
				$allowed_file_types[] = $extra;
135
			}
136
		}
137
138
		return $allowed_file_types;
139
	}
140
141
	function is_private() {
142
		return false;
143
	}
144
145
	function get_plan() {
146
		return false;
147
	}
148
149
	function get_subscribers_count() {
150
		return 0; // special magic fills this in on the WPCOM side
151
	}
152
153
	function get_capabilities() {
154
		return false;
155
	}
156
157
	function get_locale() {
158
		return get_bloginfo( 'language' );
159
	}
160
161
	function is_jetpack() {
162
		return true;
163
	}
164
165
	public function get_jetpack_version() {
166
		return JETPACK__VERSION;
167
	}
168
169
	function get_ak_vp_bundle_enabled() {}
170
171
	function get_jetpack_seo_front_page_description() {
172
		return Jetpack_SEO_Utils::get_front_page_meta_description();
173
	}
174
175
	function get_jetpack_seo_title_formats() {
176
		return Jetpack_SEO_Titles::get_custom_title_formats();
177
	}
178
179
	function get_verification_services_codes() {
180
		return get_option( 'verification_services_codes', null );
181
	}
182
183
	function get_podcasting_archive() {
184
		return null;
185
	}
186
187
	function is_connected_site() {
188
		return true;
189
	}
190
191
	function current_user_can( $role ) {
192
		return current_user_can( $role );
193
	}
194
195
	/**
196
	 * Check if full site editing should be considered as currently active. Full site editing
197
	 * requires the FSE plugin to be installed and activated, as well the current
198
	 * theme to be FSE compatible. The plugin can also be explicitly disabled via the
199
	 * a8c_disable_full_site_editing filter.
200
	 *
201
	 * @since 7.7.0
202
	 *
203
	 * @return bool true if full site editing is currently active.
204
	 */
205
	function is_fse_active() {
206
		if ( ! Jetpack::is_plugin_active( 'full-site-editing/full-site-editing-plugin.php' ) ) {
207
			return false;
208
		}
209
		return function_exists( '\A8C\FSE\is_full_site_editing_active' ) && \A8C\FSE\is_full_site_editing_active();
210
	}
211
212
	/**
213
	 * Check if site should be considered as eligible for full site editing. Full site editing
214
	 * requires the FSE plugin to be installed and activated. For this method to return true
215
	 * the current theme does not need to be FSE compatible. The plugin can also be explicitly
216
	 * disabled via the a8c_disable_full_site_editing filter.
217
	 *
218
	 * @since 8.1.0
219
	 *
220
	 * @return bool true if site is eligible for full site editing
221
	 */
222
	public function is_fse_eligible() {
223
		if ( ! Jetpack::is_plugin_active( 'full-site-editing/full-site-editing-plugin.php' ) ) {
224
			return false;
225
		}
226
		return function_exists( '\A8C\FSE\is_site_eligible_for_full_site_editing' ) && \A8C\FSE\is_site_eligible_for_full_site_editing();
227
	}
228
229
	/**
230
	 * Return the last engine used for an import on the site.
231
	 *
232
	 * This option is not used in Jetpack.
233
	 */
234
	function get_import_engine() {
235
		return null;
236
	}
237
238
	/**
239
	 * Post functions
240
	 */
241
242
	function wrap_post( $post, $context ) {
243
		return new Jetpack_Post( $this, $post, $context );
244
	}
245
246
}
247