Complex classes like Jetpack_Cxn_Test_Base 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_Cxn_Test_Base, and based on these observations, apply Extract Interface, too.
| 1 | <?php  | 
            ||
| 18 | class Jetpack_Cxn_Test_Base { | 
            ||
| 19 | |||
| 20 | /**  | 
            ||
| 21 | * Tests to run on the Jetpack connection.  | 
            ||
| 22 | *  | 
            ||
| 23 | * @var array $tests  | 
            ||
| 24 | */  | 
            ||
| 25 | protected $tests = array();  | 
            ||
| 26 | |||
| 27 | /**  | 
            ||
| 28 | * Results of the Jetpack connection tests.  | 
            ||
| 29 | *  | 
            ||
| 30 | * @var array $results  | 
            ||
| 31 | */  | 
            ||
| 32 | protected $results = array();  | 
            ||
| 33 | |||
| 34 | /**  | 
            ||
| 35 | * Status of the testing suite.  | 
            ||
| 36 | *  | 
            ||
| 37 | * Used internally to determine if a test should be skipped since the tests are already failing. Assume passing.  | 
            ||
| 38 | *  | 
            ||
| 39 | * @var bool $pass  | 
            ||
| 40 | */  | 
            ||
| 41 | protected $pass = true;  | 
            ||
| 42 | |||
| 43 | /**  | 
            ||
| 44 | * Jetpack_Cxn_Test constructor.  | 
            ||
| 45 | */  | 
            ||
| 46 | 	public function __construct() { | 
            ||
| 50 | |||
| 51 | /**  | 
            ||
| 52 | * Adds a new test to the Jetpack Connection Testing suite.  | 
            ||
| 53 | *  | 
            ||
| 54 | * @since 7.1.0  | 
            ||
| 55 | * @since 7.3.0 Adds name parameter and returns WP_Error on failure.  | 
            ||
| 56 | *  | 
            ||
| 57 | * @param callable $callable Test to add to queue.  | 
            ||
| 58 | * @param string $name Unique name for the test.  | 
            ||
| 59 | * @param string $type Optional. Core Site Health type: 'direct' if test can be run during initial load or 'async' if test should run async.  | 
            ||
| 60 | * @param array $groups Optional. Testing groups to add test to.  | 
            ||
| 61 | *  | 
            ||
| 62 | * @return mixed True if successfully added. WP_Error on failure.  | 
            ||
| 63 | */  | 
            ||
| 64 | 	public function add_test( $callable, $name, $type = 'direct', $groups = array( 'default' ) ) { | 
            ||
| 83 | |||
| 84 | /**  | 
            ||
| 85 | * Lists all tests to run.  | 
            ||
| 86 | *  | 
            ||
| 87 | * @since 7.3.0  | 
            ||
| 88 | *  | 
            ||
| 89 | * @param string $type Optional. Core Site Health type: 'direct' or 'async'. All by default.  | 
            ||
| 90 | * @param string $group Optional. A specific testing group. All by default.  | 
            ||
| 91 | *  | 
            ||
| 92 | * @return array $tests Array of tests with test information.  | 
            ||
| 93 | */  | 
            ||
| 94 | 	public function list_tests( $type = 'all', $group = 'all' ) { | 
            ||
| 118 | |||
| 119 | /**  | 
            ||
| 120 | * Run a specific test.  | 
            ||
| 121 | *  | 
            ||
| 122 | * @since 7.3.0  | 
            ||
| 123 | *  | 
            ||
| 124 | * @param string $name Name of test.  | 
            ||
| 125 | *  | 
            ||
| 126 | 	 * @return mixed $result Test result array or WP_Error if invalid name. { | 
            ||
| 127 | * @type string $name Test name  | 
            ||
| 128 | * @type mixed $pass True if passed, false if failed, 'skipped' if skipped.  | 
            ||
| 129 | * @type string $message Human-readable test result message.  | 
            ||
| 130 | * @type string $resolution Human-readable resolution steps.  | 
            ||
| 131 | * }  | 
            ||
| 132 | */  | 
            ||
| 133 | 	public function run_test( $name ) { | 
            ||
| 140 | |||
| 141 | /**  | 
            ||
| 142 | * Runs the Jetpack connection suite.  | 
            ||
| 143 | */  | 
            ||
| 144 | 	public function run_tests() { | 
            ||
| 154 | |||
| 155 | /**  | 
            ||
| 156 | * Returns the full results array.  | 
            ||
| 157 | *  | 
            ||
| 158 | * @param string $group Testing group whose results we want. Defaults to "default" group. Use "all" for all tests.  | 
            ||
| 159 | * @return array Array of test results.  | 
            ||
| 160 | */  | 
            ||
| 161 | 	public function raw_results( $group = 'default' ) { | 
            ||
| 180 | |||
| 181 | /**  | 
            ||
| 182 | * Returns the status of the connection suite.  | 
            ||
| 183 | *  | 
            ||
| 184 | * @param string $group Testing group to check status of. Optional, default all tests.  | 
            ||
| 185 | *  | 
            ||
| 186 | * @return true|array True if all tests pass. Array of failed tests.  | 
            ||
| 187 | */  | 
            ||
| 188 | 	public function pass( $group = 'default' ) { | 
            ||
| 201 | |||
| 202 | /**  | 
            ||
| 203 | * Return array of failed test messages.  | 
            ||
| 204 | *  | 
            ||
| 205 | * @param string $group Testing group whose failures we want. Defaults to "default". Use "all" for all tests.  | 
            ||
| 206 | *  | 
            ||
| 207 | * @return false|array False if no failed tests. Otherwise, array of failed tests.  | 
            ||
| 208 | */  | 
            ||
| 209 | 	public function list_fails( $group = 'default' ) { | 
            ||
| 221 | |||
| 222 | /**  | 
            ||
| 223 | * Helper function to return consistent responses for a passing test.  | 
            ||
| 224 | *  | 
            ||
| 225 | * @param string $name Test name.  | 
            ||
| 226 | *  | 
            ||
| 227 | * @return array Test results.  | 
            ||
| 228 | */  | 
            ||
| 229 | 	public static function passing_test( $name = 'Unnamed' ) { | 
            ||
| 237 | |||
| 238 | /**  | 
            ||
| 239 | * Helper function to return consistent responses for a skipped test.  | 
            ||
| 240 | *  | 
            ||
| 241 | * @param string $name Test name.  | 
            ||
| 242 | * @param string $message Reason for skipping the test. Optional.  | 
            ||
| 243 | *  | 
            ||
| 244 | * @return array Test results.  | 
            ||
| 245 | */  | 
            ||
| 246 | 	public static function skipped_test( $name = 'Unnamed', $message = false ) { | 
            ||
| 254 | |||
| 255 | /**  | 
            ||
| 256 | * Helper function to return consistent responses for a failing test.  | 
            ||
| 257 | *  | 
            ||
| 258 | * @since 7.1.0  | 
            ||
| 259 | * @since 7.3.0 Added $action for resolution action link, $severity for issue severity.  | 
            ||
| 260 | *  | 
            ||
| 261 | * @param string $name Test name.  | 
            ||
| 262 | * @param string $message Message detailing the failure.  | 
            ||
| 263 | * @param string $resolution Optional. Steps to resolve.  | 
            ||
| 264 | * @param string $action Optional. URL to direct users to self-resolve.  | 
            ||
| 265 | * @param string $severity Optional. "critical" or "recommended" for failure stats. "good" for passing.  | 
            ||
| 266 | *  | 
            ||
| 267 | * @return array Test results.  | 
            ||
| 268 | */  | 
            ||
| 269 | 	public static function failing_test( $name, $message, $resolution = false, $action = false, $severity = 'critical' ) { | 
            ||
| 292 | |||
| 293 | /**  | 
            ||
| 294 | * Provide WP_CLI friendly testing results.  | 
            ||
| 295 | *  | 
            ||
| 296 | * @param string $group Testing group whose results we are outputting. Default "default". Use "all" for all tests.  | 
            ||
| 297 | */  | 
            ||
| 298 | 	public function output_results_for_cli( $group = 'default' ) { | 
            ||
| 320 | |||
| 321 | /**  | 
            ||
| 322 | * Output results of failures in format expected by Core's Site Health tool.  | 
            ||
| 323 | *  | 
            ||
| 324 | * Specifically not asking for a testing group since we're opinionated that Site Heath should see all.  | 
            ||
| 325 | *  | 
            ||
| 326 | * @return array Array of test results  | 
            ||
| 327 | */  | 
            ||
| 328 | 	public function output_results_for_core_site_health() { | 
            ||
| 382 | |||
| 383 | /**  | 
            ||
| 384 | * Provide single WP Error instance of all failures.  | 
            ||
| 385 | *  | 
            ||
| 386 | * @param string $group Testing group whose failures we want converted. Default "default". Use "all" for all tests.  | 
            ||
| 387 | *  | 
            ||
| 388 | * @return WP_Error|false WP_Error with all failed tests or false if there were no failures.  | 
            ||
| 389 | */  | 
            ||
| 390 | 	public function output_fails_as_wp_error( $group = 'default' ) { | 
            ||
| 412 | |||
| 413 | /**  | 
            ||
| 414 | * Encrypt data for sending to WordPress.com.  | 
            ||
| 415 | *  | 
            ||
| 416 | * @todo When PHP minimum is 5.3+, add cipher detection to use an agreed better cipher than RC4. RC4 should be the last resort.  | 
            ||
| 417 | *  | 
            ||
| 418 | * @param string $data Data to encrypt with the WP.com Public Key.  | 
            ||
| 419 | *  | 
            ||
| 420 | * @return false|array False if functionality not available. Array of encrypted data, encryption key.  | 
            ||
| 421 | */  | 
            ||
| 422 | 	public function encrypt_string_for_wpcom( $data ) { | 
            ||
| 443 | }  | 
            ||
| 444 | 
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.