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 | * Determine if the login form should be hidden or not | ||
| 13 | * | ||
| 14 | * @return bool | ||
| 15 | **/ | ||
| 16 | 	static function should_hide_login_form() { | ||
| 28 | |||
| 29 | /** | ||
| 30 | * Returns a boolean value for whether logging in by matching the WordPress.com user email to a | ||
| 31 | * Jetpack site user's email is allowed. | ||
| 32 | * | ||
| 33 | * @return bool | ||
| 34 | */ | ||
| 35 | 	static function match_by_email() { | ||
| 50 | |||
| 51 | /** | ||
| 52 | * Returns a boolean for whether users are allowed to register on the Jetpack site with SSO, | ||
| 53 | * even though the site disallows normal registrations. | ||
| 54 | * | ||
| 55 | * @return bool | ||
| 56 | */ | ||
| 57 | 	static function new_user_override( $user_data = null ) { | ||
| 84 | |||
| 85 | /** | ||
| 86 | * Returns a boolean value for whether two-step authentication is required for SSO. | ||
| 87 | * | ||
| 88 | * @since 4.1.0 | ||
| 89 | * | ||
| 90 | * @return bool | ||
| 91 | */ | ||
| 92 | 	static function is_two_step_required() { | ||
| 104 | |||
| 105 | /** | ||
| 106 | * Returns a boolean for whether a user that is attempting to log in will be automatically | ||
| 107 | * redirected to WordPress.com to begin the SSO flow. | ||
| 108 | * | ||
| 109 | * @return bool | ||
| 110 | */ | ||
| 111 | 	static function bypass_login_forward_wpcom() { | ||
| 123 | |||
| 124 | /** | ||
| 125 | * Returns a boolean for whether the SSO login form should be displayed as the default | ||
| 126 | * when both the default and SSO login form allowed. | ||
| 127 | * | ||
| 128 | * @since 4.1.0 | ||
| 129 | * | ||
| 130 | * @return bool | ||
| 131 | */ | ||
| 132 | 	static function show_sso_login() { | ||
| 148 | |||
| 149 | /** | ||
| 150 | * Returns a boolean for whether the two step required checkbox, displayed on the Jetpack admin page, should be disabled. | ||
| 151 | * | ||
| 152 | * @since 4.1.0 | ||
| 153 | * | ||
| 154 | * @return bool | ||
| 155 | */ | ||
| 156 | 	static function is_require_two_step_checkbox_disabled() { | ||
| 159 | |||
| 160 | /** | ||
| 161 | * Returns a boolean for whether the match by email checkbox, displayed on the Jetpack admin page, should be disabled. | ||
| 162 | * | ||
| 163 | * @since 4.1.0 | ||
| 164 | * | ||
| 165 | * @return bool | ||
| 166 | */ | ||
| 167 | 	static function is_match_by_email_checkbox_disabled() { | ||
| 170 | |||
| 171 | /** | ||
| 172 | * Returns an array of hosts that SSO will redirect to. | ||
| 173 | * | ||
| 174 | * Instead of accessing JETPACK__API_BASE within the method directly, we set it as the | ||
| 175 | * default for $api_base due to restrictions with testing constants in our tests. | ||
| 176 | * | ||
| 177 | * @since 4.3.0 | ||
| 178 | * @since 4.6.0 Added public-api.wordpress.com as an allowed redirect | ||
| 179 | * | ||
| 180 | * @param array $hosts | ||
| 181 | * @param string $api_base | ||
| 182 | * | ||
| 183 | * @return array | ||
| 184 | */ | ||
| 185 | 	static function allowed_redirect_hosts( $hosts, $api_base = JETPACK__API_BASE ) { | ||
| 203 | |||
| 204 | 	static function generate_user( $user_data ) { | ||
| 245 | |||
| 246 | 	static function extend_auth_cookie_expiration_for_sso() { | ||
| 259 | |||
| 260 | /** | ||
| 261 | * Determines if the SSO form should be displayed for the current action. | ||
| 262 | * | ||
| 263 | * @since 4.6.0 | ||
| 264 | * | ||
| 265 | * @param string $action | ||
| 266 | * | ||
| 267 | * @return bool Is SSO allowed for the current action? | ||
| 268 | */ | ||
| 269 | 	static function display_sso_form_for_action( $action ) { | ||
| 286 | |||
| 287 | /** | ||
| 288 | * Checks the initial `$_REQUEST` to see if `?connect` was set explicitly. | ||
| 289 | * | ||
| 290 | * Default behavior is to connect every SSO request, but if `?connect=0` | ||
| 291 | * (or another falsy value) then we allow a user to log in without connecting. | ||
| 292 | * | ||
| 293 | * @since 6.8 | ||
| 294 | * | ||
| 295 | * @return bool | ||
| 296 | */ | ||
| 297 | 	static function should_connect() { | ||
| 318 | |||
| 319 | /** | ||
| 320 | * This method returns an environment array that is meant to simulate `$_REQUEST` when the initial | ||
| 321 | * JSON API auth request was made. | ||
| 322 | * | ||
| 323 | * @since 4.6.0 | ||
| 324 | * | ||
| 325 | * @return array|bool | ||
| 326 | */ | ||
| 327 | 	static function get_json_api_auth_environment() { | ||
| 355 | } | ||
| 356 | |||
| 358 |