Complex classes like Jetpack_SSO_Helpers 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_SSO_Helpers, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
10 | class Jetpack_SSO_Helpers { |
||
11 | /** |
||
12 | * An array used to store the contents of $_GET before overriding $_GET. |
||
13 | * @var array |
||
14 | */ |
||
15 | static $stashed_get_params = array(); |
||
|
|||
16 | |||
17 | /** |
||
18 | * An array used to store the content of $_POST before overriding $_POST. |
||
19 | * @var array |
||
20 | */ |
||
21 | static $stashed_post_params = array(); |
||
22 | |||
23 | /** |
||
24 | * Determine if the login form should be hidden or not |
||
25 | * |
||
26 | * @return bool |
||
27 | **/ |
||
28 | static function should_hide_login_form() { |
||
40 | |||
41 | /** |
||
42 | * Returns a boolean value for whether logging in by matching the WordPress.com user email to a |
||
43 | * Jetpack site user's email is allowed. |
||
44 | * |
||
45 | * @return bool |
||
46 | */ |
||
47 | static function match_by_email() { |
||
62 | |||
63 | /** |
||
64 | * Returns a boolean for whether users are allowed to register on the Jetpack site with SSO, |
||
65 | * even though the site disallows normal registrations. |
||
66 | * |
||
67 | * @return bool |
||
68 | */ |
||
69 | static function new_user_override( $user_data = null ) { |
||
96 | |||
97 | /** |
||
98 | * Returns a boolean value for whether two-step authentication is required for SSO. |
||
99 | * |
||
100 | * @since 4.1.0 |
||
101 | * |
||
102 | * @return bool |
||
103 | */ |
||
104 | static function is_two_step_required() { |
||
116 | |||
117 | /** |
||
118 | * Returns a boolean for whether a user that is attempting to log in will be automatically |
||
119 | * redirected to WordPress.com to begin the SSO flow. |
||
120 | * |
||
121 | * @return bool |
||
122 | */ |
||
123 | static function bypass_login_forward_wpcom() { |
||
135 | |||
136 | /** |
||
137 | * Returns a boolean for whether the SSO login form should be displayed as the default |
||
138 | * when both the default and SSO login form allowed. |
||
139 | * |
||
140 | * @since 4.1.0 |
||
141 | * |
||
142 | * @return bool |
||
143 | */ |
||
144 | static function show_sso_login() { |
||
160 | |||
161 | /** |
||
162 | * Returns a boolean for whether the two step required checkbox, displayed on the Jetpack admin page, should be disabled. |
||
163 | * |
||
164 | * @since 4.1.0 |
||
165 | * |
||
166 | * @return bool |
||
167 | */ |
||
168 | static function is_require_two_step_checkbox_disabled() { |
||
171 | |||
172 | /** |
||
173 | * Returns a boolean for whether the match by email checkbox, displayed on the Jetpack admin page, should be disabled. |
||
174 | * |
||
175 | * @since 4.1.0 |
||
176 | * |
||
177 | * @return bool |
||
178 | */ |
||
179 | static function is_match_by_email_checkbox_disabled() { |
||
182 | |||
183 | /** |
||
184 | * Returns an array of hosts that SSO will redirect to. |
||
185 | * |
||
186 | * Instead of accessing JETPACK__API_BASE within the method directly, we set it as the |
||
187 | * default for $api_base due to restrictions with testing constants in our tests. |
||
188 | * |
||
189 | * @since 4.3.0 |
||
190 | * @since 4.6.0 Added public-api.wordpress.com as an allowed redirect |
||
191 | * |
||
192 | * @param array $hosts |
||
193 | * @param string $api_base |
||
194 | * |
||
195 | * @return array |
||
196 | */ |
||
197 | static function allowed_redirect_hosts( $hosts, $api_base = JETPACK__API_BASE ) { |
||
218 | |||
219 | static function generate_user( $user_data ) { |
||
262 | |||
263 | static function extend_auth_cookie_expiration_for_sso() { |
||
275 | |||
276 | /** |
||
277 | * Determines if the SSO form should be displayed for the current action. |
||
278 | * |
||
279 | * @param string $action |
||
280 | * |
||
281 | * @return bool Is SSO allowed for the current action? |
||
282 | */ |
||
283 | static function display_sso_form_for_action( $action ) { |
||
299 | |||
300 | /** |
||
301 | * Given a URL that is the original request which kicked off the SSO flow, this function returns whether |
||
302 | * the request was for Jetpack JSON API authorization by checking the value of `$action`. |
||
303 | * |
||
304 | * @param string $original_request |
||
305 | * |
||
306 | * @return bool Was the original request for JSON API authorization? |
||
307 | */ |
||
308 | static function is_sso_for_json_api_auth( $original_request ) { |
||
325 | |||
326 | /** |
||
327 | * Given a URL that is the original request which kicked off the SSO flow, this function stores the contents of |
||
328 | * $_GET and $_POST into static variables of this class and then updates $_GET and $_POST to match the original |
||
329 | * request. This is done so that we can verify the JSON API authorization request. |
||
330 | * |
||
331 | * @param string $original_request |
||
332 | * |
||
333 | * @return bool Were the superglobal values updated to mathch the original request? |
||
334 | */ |
||
335 | static function set_superglobal_values_for_json_api_auth( $original_request ) { |
||
362 | |||
363 | /** |
||
364 | * This function is meant to be run after calling self::set_superglobal_values_for_json_api_auth( $original_request) |
||
365 | * and resets the superglobals back to their original values. |
||
366 | */ |
||
367 | static function reset_superglobal_values_after_json_api_auth() { |
||
371 | } |
||
372 | |||
374 |
The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using
the property is implicitly global.
To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.